To be truly MVC?

To be truly MVC should I use the model to talk to the sessions of CI? Or is that a controller part. I know the model is the layer that talks to the database. I am not currently storing session data in the database only the cookie, should I use the model or controller to be MVC?

I am new to the MVC way of thinking so I'm unclear on this particular element.

Thanks in advance.

There's no such thing as "truly MVC". MVC is a design pattern that was implemented by CI in a certain way and has some principles you can adhere to. But you can also be flexible and not too rigid, just think carefully if things make sense.

The way I look at it (and some might disagree with me):
- The controller is the base of any request the user makes. It's the place for logic and not the place for DB queries and the like. For those you should load other resources like models and libraries that simplify the code in the controller and prevent you from needing to copy paste the same code in multiple methods/controllers.
- The model is pretty much single-minded and should (in my opinion) only have knowledge about it's own type of data, whether that be a database table, the filesystem, or another resource. I prefer to put pretty much anything related in there, including the validation rules and specilialized validation methods.

With those 2 principles I'd suggest you collect all data in your controller and push it to the model when needed. But that's not a cut in stone principle. If the session data is specific to your model it belongs with the model in my opinion.

In the end the most important thing is to think carefully for yourself if what you're doing feel logical. When it doesn't or when your copy-pasting code it's time to take a step back and think carefully about how to proceed.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.