CodeIgniter Forums
Best MVC practice - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Best MVC practice (/showthread.php?tid=54963)



Best MVC practice - El Forum - 10-03-2012

[eluser]snoo[/eluser]
Hi Guys,

I'm new to the whole MVC structure and to coding in general. I'm a little confused and would like to know the best practice on where to keep my code so that it is clean and easy to maintain.

So far with CI, this is what I've been doing.

View: html and printing variables passed from controller.

Controller: controls what data to show / action to take base on user action

Model: retrieve data from database and send it to controller.

Because of my current practice, my model is usually pretty slim, consist of standard CRUD functions and variations of it. On the other hand, my controller is usually fat and bulky due to having to parse inputs and segments and assemble arrays and variables so view can easily print out without having to do much php init.

Is this normal, or should I use model to do some of the logic work I'm currently doing on controller?

Thanks for any input.

William


Best MVC practice - El Forum - 10-03-2012

[eluser]TWP Marketing[/eluser]
It may not be "pure" MVC, but I use my model(s) for massaging data after retrieval from the db. This keeps my controller code leaner and helps me to understand my own code after some time has passed. I also use model methods to construct data arrays and read configuration values (which I consider part of my 'database').