Include a model class without initialize it. |
[eluser]megablue[/eluser]
I want to extend a model class but somehow $this->load->model() will initialize it as an object. Is there anyway to do it with CI or do I need to use include()?
[eluser]megablue[/eluser]
I tried another way which i still run into a problem. I tried to load the base model as usual. $this->load->model('the_base_model', 'basename'); then I tried to unload the base model in order to load the extended model; unset($this->basename); //the_extended_model is extended from the_base_model $this->load->model('the_extended_model', 'basename'); Yet the extended model is unable to initialize. It can work if I give the 'basename' a name change. So is that means CI keeps track of a list of declared object name somewhere and prevent it from redeclaring?
[eluser]danmontgomery[/eluser]
Yes, CI keeps a list of instantiated object. You should be using the subclass_prefix setting in config/config.php, then loading the model normally (http://ellislab.com/codeigniter/user-gui...aries.html). If your subclass_prefix is MY_ (default), you would have MY_Model as your base class, then you would extend that class, and load it normally. MY_Model.php Code: class MY_Model extends Model { other_model.php Code: class Other_model extends MY_Model { Controller Code: $this->load->model('other_model')
[eluser]megablue[/eluser]
[quote author="noctrum" date="1281980046"]Yes, CI keeps a list of instantiated object. You should be using the subclass_prefix setting in config/config.php, then loading the model normally (http://ellislab.com/codeigniter/user-gui...aries.html). If your subclass_prefix is MY_ (default), you would have MY_Model as your base class, then you would extend that class, and load it normally. MY_Model.php Code: class MY_Model extends Model { other_model.php Code: class Other_model extends MY_Model { Controller Code: $this->load->model('other_model') Yes, i knew about extending the CI base model with CI way. However i have a fairly dynamic application that requires multiple 'base models' base on different situations. Some models share fair amount of code even their default methods, some are distinctly different. |
Welcome Guest, Not a member yet? Register Sign In |