Introduction
The Model-View-Controller approach has been in my head since before the holidays and I really need to get it down to a tee within my web application, created in PHP.
So far, I understand the general MVC Concept and why it's done, but I need some help. This is a University project, and my project adviser is not very helpful when I ask questions about MVC.
The Application
It's a task management system, or a to-do list. The aim is a very simple interface where the user can login with their Facebook account, create, modify or remove tasks, and logout, created with Javascript and PHP.
The Facts
I have a static PHP page here containing divs like "top_div" and "main_div". The aim is for "controller.php" to be included (I haven't created this yet) to serve between the view and the model.
Important: Everything on the page uses jQuery, so the user will never see a page refresh. I have a function that fades out the content in a div, grabs the newly required content, places it in the div (hidden, because the div has faded out), then fades in the div again.
The aim is for the controller to request from the model, then send back (for example) a Facebook login button to the view. This Facebook Login button is HTML. There will be others like text and html for the content, and if the user is already logged in "Welcome " will be sent to the #main_div using PHP, jQuery and cURL.
I am using objects, so from what I understand I will need to instantiate an object to do the database connection and queries. Where do I instantiate objects? I read that they are supposed to be created in the controller, but from everything else I've read the controller is meant to be simple, telling the model what the view wants acting only as the go-between. I was under the impression (and it makes more sense to me) for the model to instantiate objects.
1) So, please explain to me how it would be incorrect to instantiate objects in the model. If this wasn't the case, that'd be great as far as my understanding of the MVC approach goes.
Lets say the user has logged in. I will be displaying their name, and their Facebook picture on the view (index.php). If you visit the site on the link above you may see a small white box on the right where this picture will go. The code for the user's picture in PHP looks like this:
<img src="https://graph.facebook.com/'.$fbid.'/picture" width="79" height="64" align="center" style="opacity:0.8;">';
2) As this HTML will be passed to the view to be displayed into a DIV using the jQuery function described above, is it okay for my controller to have this sort of information going out? My controller may have something along the lines of (pseduo code):
if(user is logged in(from checking via model)) then { send to #main_div the html above };
I may think of loads more questions along the way with this, but please can someone help me understand more about what I'm doing?