Welcome Guest, Not a member yet? Register   Sign In
Libraries or Models, favouritism?
#8

[eluser]Hyra[/eluser]
Well yes.

So, again .. the phone number example. Would this be the way to set it up?

[Controller] contact.php
Code:
// Get posted vars, validation, etc.

// Call a library
$this->load->library('val_phone');
$is_valid_phone = $this->val_phone->check($this->validation->phone_number);

// Do something according to BOOL

[Library] val_phone.php
Code:
function check($nr) {
  // !! This is dodgy! OPTIONAL USE OF MODEL?
  $valid = $this->some_model->getRanges('phone_ranges');
  if(in_array(substr($nr, 0, 3), $valid)) {
     if(reg_exp('#4/\g\n.gdd[3]d')) {
        return TRUE;
     }
  }
  return FALSE;
}

[Model] not_sure_what_to_call_it.php
Code:
function getRanges($from) {
   // Do database stuff
   return $array;
}

So this would mean the library depends on a model as well, thus not making it very portable. That's what was confusing me. Should the library contain database actions like the above, or should it really really go into a model, even though it only contains one simple database function.

Putting the db query inside the library would make it far more plug 'n play.


Messages In This Thread
Libraries or Models, favouritism? - by El Forum - 02-25-2008, 08:28 AM
Libraries or Models, favouritism? - by El Forum - 02-25-2008, 10:41 AM
Libraries or Models, favouritism? - by El Forum - 02-25-2008, 10:46 AM
Libraries or Models, favouritism? - by El Forum - 02-25-2008, 02:59 PM
Libraries or Models, favouritism? - by El Forum - 02-25-2008, 04:54 PM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 01:33 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 01:43 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 02:13 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 02:24 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 03:05 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 03:20 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 03:34 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 03:42 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 03:50 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 04:26 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 08:08 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 08:40 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 10:23 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 10:33 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 11:34 AM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 01:01 PM
Libraries or Models, favouritism? - by El Forum - 02-26-2008, 01:41 PM
Libraries or Models, favouritism? - by El Forum - 03-29-2008, 10:14 PM
Libraries or Models, favouritism? - by El Forum - 03-29-2008, 10:26 PM
Libraries or Models, favouritism? - by El Forum - 03-29-2008, 10:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB