Welcome Guest, Not a member yet? Register   Sign In
How models and the such exactly work in CI
#1

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB