Welcome Guest, Not a member yet? Register   Sign In
Autoloading Models
#1

[eluser]adamp1[/eluser]
After implementing the auto loading feature described here I get an error. What happens is a model is auto loaded and in it the model uses the database call ($this->db->get()Wink to fetch records.

What I think is happening is when this error occurs the database library hasn't been loaded yet, since in the loader.php class it is loaded after the models.

How can I auto load a model which needs to use the database and not get this error? I did try putting $this->load->database() into the constructor function of the model but that did nothing either.
#2

[eluser]Derek Allard[/eluser]
Try the advice here: http://ellislab.com/forums/viewthread/63795/
#3

[eluser]barbazul[/eluser]
i noticed this change a week ago or so and at the moment i thought the autoloading order felt wrong for some reason.
Now I see why.

Models work somewhat different than the other objects that get appended to the controller object: enything on the controller gets appended to them also.
So, when working with models, you assume that any loaded library is available within the model. That should remain true to autoloaded libraries/models since the process of autoloading is "transparent" to the developer. The developer shouldn't really care of the autoloading order.

I tried moving the model autoloading to the end of the _ci_autoloader method. It didn't work at first, but then I realised that in the haste of preparing the example I forgot to call parent::Model() at the begining of the model constructor.
Added that line and now the fix seems to work smoothly

what do you think?




Theme © iAndrew 2016 - Forum software by © MyBB