CodeIgniter Forums
autoload model using CI standards? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: autoload model using CI standards? (/showthread.php?tid=22897)



autoload model using CI standards? - El Forum - 09-23-2009

[eluser]jof[/eluser]
Hi all

One week has passed for me using the CI :-) Trying to port my zend framwork project, no prolems at all. but one small thing:

Is there any way for me to autoload the models if I name the correct CI standard?

To me it's seems unnecessary to call the models in every controller if I use one-to-one all the time?

Code:
controller: text.php
model: text_model.php

regards // Johannes


autoload model using CI standards? - El Forum - 09-23-2009

[eluser]darkhouse[/eluser]
A couple issues. First, it's only 1 line of code to load a model, and you can do it in the constructor, not a big deal. Second, I don't think models and controllers should be used as one-to-one all the time. I think models should be used for data "groups", like users, news, etc. A news model, you might only need for 1 page, but a users model you would likely need all over the site.

Just my opinion I guess.


autoload model using CI standards? - El Forum - 09-23-2009

[eluser]jof[/eluser]
Thanks for the reply to this.

No its not the one line code that is hard to write :-) But if I do it all the time it's wise to let the framework do it? Or at least have the option to autoload.

My "overall" approach to mvc is to try to have the one-to-one, and if a class is used by many, I usually put it in the librarys, create a util lib or specific libs. So the librarys is sort of "globl" and models stick to their controller.

works for me ;-)

regards // johannes


autoload model using CI standards? - El Forum - 09-23-2009

[eluser]darkhouse[/eluser]
I guess to each their own. My interpretation on MVC is that models are used for data manipulation, so grouping related data into models makes sense to me. Libraries are for adding new functionality to the framework.

Maybe you can write and autoload a library to grab the uri, pull out the controller name, and autoload the model.


autoload model using CI standards? - El Forum - 09-23-2009

[eluser]n0xie[/eluser]
http://www.michaelwales.com/codeigniter/codeigniter-convention-over-configuration


autoload model using CI standards? - El Forum - 09-23-2009

[eluser]jof[/eluser]
aha - great!


autoload model using CI standards? - El Forum - 09-23-2009

[eluser]darkhouse[/eluser]
Oh yeah, I guess that makes more sense, extend the controller.