Page 1 of 1

MVC and the different dynamic sections of their web app

Posted: Wed Feb 28, 2007 7:26 am
by crabby80
Hi Guys

Could someone explain how they build the different dynamic sections of their web app using MVC?

If my web appllication consisted of 3 columns how would I incorporate the other controllers for the side columns as well as the main content controller?

I.E

//Request http://www.domainname.co.uk/players/all

I would need a players controller for the main content, then how would I incorporate a latest news controller, top ten players controller, press articles controller etc for the side bars?

I've heard of the composite view but it doesn't make sense to me :?
Confused

I hope this is clear

Any help would be much appreciated

Kind Regards

T

Posted: Wed Feb 28, 2007 12:11 pm
by Christopher
Your three columns sound like separate Views, not Controllers. A View object has all the presentation logic in it needed to generate the output for that specific thing.

Posted: Thu Mar 01, 2007 8:43 am
by crabby80
Hi arborint

Thanks for your reply.

But how is this pulled together?

Would you have something like a template/mainpage controller that uses the specific models and views for each section?

Posted: Thu Mar 01, 2007 12:10 pm
by Begby
A controller acts to pull data together and construct a view. What the user sees is a single view and what appears to be a set of data.

Behind the scenes though the data can come from many spots, a set of database tables, an RSS feed, or whatever. The data is your model.

The view can be one template file or several template files that are put or data that is just echoed by the controller if you are hackish.

There should only be one controller method called that constructs the page, not many calls to many controllers.


So what you need to do is create templates for each of the parts of the page that you want to reuse, have the controller get the data needed for each part from the model, then render them. So you can create a model that gets your news data, a view that takes the data sent to it and turns it into an HTML snippet, then a model for players and a view etc. Then you are going to take the HTML generated by each of your views and stick it together into one nice web page.

If you are still confused you might want to read up a little bit about MVC on the web.

Posted: Fri Mar 02, 2007 4:38 am
by crabby80
Hi Begby

Thank you for reply

Makes sense

If certain elements were common throughout the site would it make sense to have a parent page controller that each controller could inherit from?