Welcome Guest, Not a member yet? Register   Sign In
Models, where, when and why?
#15

Thyrosis, think about it this way. We'll start off with the router. So someone arrives at your URL looking for a blog post. The router nudges the blog controller and says, "Oi someone want a blog post. You can find the post ID here." The controller grabs the ID then goes to the blog model, and says, "Hello blog model, can you see if you can find this blog post for me please?". The blog model takes the post ID from the controller, runs it under the tap to clean it off (just in case someone stuck a bogie on it), then it looks for the post in the database. The blog model finds the post data, grabs it, grabs all the info associated with it, then asks the user model to hand over the info for the author of the blog post. Then it sees it needs to get the user's avatar image too, so then the blog model goes to the image library and asks it to check if the user's avatar file exists, and to create a URL to it. The image library is only too happy to oblige. The blog model now has everything the controller expects, and so it packages it up into an array, and says, "Here you go blog controller. This is all the blog info." The blog controller grabs it, says "Thanks for that mate!" and shakes the blog post view and says, "Oi view wake up! You need to show this to a visitor. Take this array and render your stuff!". The view takes the array and renders it's stuff, and they all live happily ever after.

So you can see the proper relational use between MVC here and also the involvement of other libraries you may have created to do specific tasks that could be re-used in other applications.

While that is the intended way of doing things, CI is very flexible, and doesn't force you to do anything. If you wanted to, you could have done everything, including displaying the HTML output with just the controller, but there wouldn't be any point in using CI at all if you were to do that.
Reply


Messages In This Thread
Models, where, when and why? - by Thyrosis - 10-24-2014, 12:03 AM
RE: Models, where, when and why? - by Rufnex - 10-24-2014, 02:39 AM
RE: Models, where, when and why? - by navotjer - 10-24-2014, 04:10 AM
RE: Models, where, when and why? - by InsiteFX - 10-24-2014, 04:44 AM
RE: Models, where, when and why? - by kilishan - 10-24-2014, 08:17 AM
RE: Models, where, when and why? - by Thyrosis - 10-25-2014, 02:16 AM
RE: Models, where, when and why? - by John_Betong - 10-24-2014, 10:04 AM
RE: Models, where, when and why? - by Hobbes - 10-29-2014, 06:41 AM
RE: Models, where, when and why? - by jlp - 10-29-2014, 08:50 PM
RE: Models, where, when and why? - by albertleao - 10-30-2014, 11:41 AM
RE: Models, where, when and why? - by InsiteFX - 10-30-2014, 04:28 PM
RE: Models, where, when and why? - by Thyrosis - 11-01-2014, 01:27 AM
RE: Models, where, when and why? - by alroker - 11-16-2014, 11:55 AM
RE: Models, where, when and why? - by Thyrosis - 11-18-2014, 05:51 AM
RE: Models, where, when and why? - by RobertSF - 11-20-2014, 08:19 PM
RE: Models, where, when and why? - by veedeoo - 11-17-2014, 09:04 PM
RE: Models, where, when and why? - by bclinton - 11-17-2014, 09:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB