Welcome Guest, Not a member yet? Register   Sign In
OO usage in code igniter structure, Model, Controller
#3

[eluser]Colin Williams[/eluser]
There's no reason you cannot use this OOP style within the framework. Consider this model:

Code:
class Cat_model extends Model
{
   function new($param1, $param2)
   {
      return new Cat($param1, $param2);
   }

   function save($cat)
   {
      $this->db->insert('cat', $cat);
   }
}

class Cat {
  
   var $param1;
   var $param2;
   function Cat($param1, $param2)
   {

   }

}

And then a controller:

Code:
$cat = $this->cat_model->new('Calico', 'Freddie');
$cat->param1 = 'Black';
$this->cat_model->save($cat);

In my opinion, you don't really need the Cat class, unless you just want it for methods that set it's properties.


Messages In This Thread
OO usage in code igniter structure, Model, Controller - by El Forum - 11-14-2008, 04:07 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 02:14 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 04:33 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 04:41 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 05:28 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 06:14 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 07:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB