What is the best practices as far as storing variables in the Controller or Model?
For instance when the script is executed. it grabs the user id from the session and gets what type of user it is, Super Admin, Admin, Service Rep, Sales Rep. We also check to see what account the user id belongs too, and grab all the setting for that account.
My questions is where do i store these values, in the controller or model?
Thank you in advance.
In PHP, it is a little strange to think about a true MVC model, because your model, view, and controller can access the $_SESSION.
If, for example, you are going to log a user in, your model would do the following:
Obviously this code has to be expended upon, but it should display the concepts correctly. I also used static functions in the model, but you can make the model an object.
Depending on how you want to do it, you either fetch the settings every time form the database through the model or you can store them in the session. Storing things in the $_SESSION will allow you to have less database calls. In practice, the model manipulates the $_SESSION or the database. If your model is particular to something (you could make your own user model), then you instantiate that object and store your information in private members.
The point of the controller is to take information form the model and then render your page accordingly. Really a MVC dataflow works this way:
(this is optional, maybe the controller doesn’t need anything from the model)
(Happens if you made a request form the previous step)