skip to content

DerekAllard.com : CodeIgniter, ExpressionEngine, and the World of Web Design

Auto-Loading Models in CodeIgniter

October 09th, 2007

Quietly added, CodeIgniter now has the ability to auto-load Models.  This is super handy if you have a site-wide need for a model, say a “settings” model, or an “auth” model.  The feature will be in the next CI release*, but you can grab it now if you want to.  Just get a new copy of the Loader from the SVN (here it is), and add this into your config/autoloader.php file.

$autoload['model'= array('model1_model''model2_model'); 

And magically, your models will be autoloaded ;)  There are updated docs in the SVN also.  If you are a true nerd, you’ll might enjoy the “foreach” variables on line 112.  Well, I thought it was clever.  Anyhow, enjoy it while its hot, I have no idea if those variable names will stay the same when we release.  (Oh man, my nerd humour can be pretty lame…)

Features are slowly tricking into the SVN, and we’ve got many more goodies waiting to be released.

* I just wanted to drop an update, there is no release date established yet.

This entry was made on October 09th, 2007 @ 13:56 and filed into CodeIgniter.

Comments

Henrik wrote on October 09th, 2007 @ 14:07

I’ve been thinking about this very topic the last few days and thought that there must be a way to auto-load them… well… now I don’t have to.

Great work folks, keep it up!

CodeOfficer wrote on October 09th, 2007 @ 19:56

haha, good one. great update. this new feature will be well received. I’ve been auto-loading models via a post controller constructor hook up till now.

Speaking of auto-loading, I wrote a CI Javascripts library recently that accepts an array of JS files you would like to load (from a $config[‘javascripts’]), as well it lets you load JS files as you go in your controller ... saving them in an array for later use by the View.

If anyone is interested: http://pastie.textmate.org/pastes/105485

Shane Ross wrote on October 11th, 2007 @ 22:08

That is going to be awesome. I look forward to using that.

Shadowhand wrote on October 25th, 2007 @ 8:55

Someone should really do a “trim trailing whitespace” on the entire CI source. It seems none of the folks at Ellis Labs have “show invisibles” turned on.

Glad that CI is showing a little life again!

Adam Price wrote on November 01st, 2007 @ 14:05

I have made the changes you said, but on auto loading a model it says “Call to a member function on a non-object”. Now the function its talking about is $this->db-get(); So what seems to be happening is my database isn’t being loaded before the model is?

Any idea?

barbazul wrote on November 01st, 2007 @ 21:18

We really needed a way to autoload babes ;)

Great job Derek!!!

Post a Comment

Sorry, comments are automatically closed after 45 days, or sooner if one entry gets targetted by spammers. Why not contact me directly?