CodeIgniter Forums
How models and the such exactly work in CI - 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: How models and the such exactly work in CI (/showthread.php?tid=2182)



How models and the such exactly work in CI - El Forum - 07-20-2007

[eluser]Bobtorious[/eluser]
Hi,
First, forgive me for the noobishness of this question as I come from a desktop application development world, so the transition to the web development world has been a bit chaotic as you can imagine Smile

Does CI keep models loaded between different functions and controllers? For instance, lets say I have a user model that I instantiate when someone logs into my application. Will that user object (with it's pertinent information) be available across my various functions and controllers, or will I have to load my user model and repopulate it with the information? What I'm doing right now is, when I user logs in, I store their ID in a session, and then every time I need user information, such as name or permissions, I load the user model, grab the user id from the session, and then use my various methods I've written in my model to get the information.

I'm guess I'm asking if this is a CI best practice?

Thanks!

Bob


How models and the such exactly work in CI - El Forum - 07-20-2007

[eluser]Phil Sturgeon[/eluser]
Everthing loaded will be kept in the current "instance". Meaning Controllers, views can access anything loaded via $this or by using get_instance();

If for example you load a model or library in the constructor of the controller, it will be available to all fnuctions below it.

However they are only loaded for that page request. Click a new page which doesnt load the user model, and it wont work. Hope this makes sense.


How models and the such exactly work in CI - El Forum - 07-20-2007

[eluser]Bobtorious[/eluser]
That clarifies things greatly! Thanks for the reply.