CodeIgniter Forums
understanding Models - 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: understanding Models (/showthread.php?tid=32484)



understanding Models - El Forum - 07-25-2010

[eluser]jtan[/eluser]
I noticed that most of the time, I can run the code without actually using Models, the data can be loaded directly from Controller, what's the advantage of using Models?


understanding Models - El Forum - 07-25-2010

[eluser]WanWizard[/eluser]
If you want to can put all code is a single method in a single controller, CI is so flexible it won't stop you.

You will have to use some discipline and determine for yourself which implementation of the MVC pattern works for you. Using models and libraries, and dedicating a controller method to a single task, makes your application simple, structured, and easy to maintain.


understanding Models - El Forum - 07-25-2010

[eluser]jtan[/eluser]
can I assume models are more like extensions or libraries for Controllers?


understanding Models - El Forum - 07-25-2010

[eluser]jtan[/eluser]
any trick how to track data, sometimes i get confused with so many variables/data to pass from controller to model to views...


understanding Models - El Forum - 07-25-2010

[eluser]WanWizard[/eluser]
[quote author="jtan" date="1280068759"]can I assume models are more like extensions or libraries for Controllers?[/quote]
You normally use the controller to control the flow, use libraries for shared and/or reusable methods, and models to interact with your data.


understanding Models - El Forum - 07-25-2010

[eluser]WanWizard[/eluser]
[quote author="jtan" date="1280069004"]any trick how to track data, sometimes i get confused with so many variables/data to pass from controller to model to views...[/quote]
I don't now what you want to track.

I usually start defining my 'data' array at the begining of my method, then add elements to it as I get along, until I reach the point where I call the view, to which I pass the data array.