Welcome Guest, Not a member yet? Register   Sign In
autoload, what is your practice?
#1

[eluser]searain[/eluser]
For small to middle size project such as shopping site etc.

Should we use autoload to load all the models?

Or should we call the load->model in the controller. (it seems to me that call the load->model in the controller will not add too many lines of the codes but it seems make the code more clear. It is like the comment line telling us which model this controller is working with.

Your advices?
#2

[eluser]jedd[/eluser]
My gut feel is to autoload anything you use in more than a couple of classes .. and later on, if/when performance becomes an issue, you can revisit things on a per-controller/model basis.

It's not the most thoughtful or elegant approach - more of a pragmatic approach.
#3

[eluser]jdfwarrior[/eluser]
I dont think I would go the route of autoloading everything. I just wouldnt do that..

If you use it in multiple places in the same controller/class, just load it in the constructor rather than for every function.
If you use the same library/model in just about every controller, I would auto load it.
#4

[eluser]Dam1an[/eluser]
The only things I autoload are the session and database libraries, and the URL helper, and they get used on every page.
As for everything else, I load it as I need it in the function.

Although when I first started, I did autoload almost everything, thinking it was so awesome to no lonher have to include files all the time (or use the loader in the case of CI) but it turns out I prefer to load it where it gets used
#5

[eluser]xwero[/eluser]
Dam1an you can lazy load the database setting the third parameter of the load->model method to true.

I barely use the autoload functionality, only for the session library and helpers i think that should be loaded by a library like the url helper.
#6

[eluser]Dam1an[/eluser]
[quote author="xwero" date="1246330194"]Dam1an you can lazy load the database setting the third parameter of the load->model method to true.[/quote]

I know I can but I just prefer it this way for some reason... personal preference




Theme © iAndrew 2016 - Forum software by © MyBB