Welcome Guest, Not a member yet? Register   Sign In
autoload model using CI standards?
#1

[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
#2

[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.
#3

[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
#4

[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.
#5

[eluser]n0xie[/eluser]
http://www.michaelwales.com/codeigniter/...figuration
#6

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

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




Theme © iAndrew 2016 - Forum software by © MyBB