MVC and the different dynamic sections of their web app

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crabby80
Forum Newbie
Posts: 3
Joined: Thu Feb 08, 2007 11:29 am

MVC and the different dynamic sections of their web app

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
crabby80
Forum Newbie
Posts: 3
Joined: Thu Feb 08, 2007 11:29 am

Post 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?
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post 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.
crabby80
Forum Newbie
Posts: 3
Joined: Thu Feb 08, 2007 11:29 am

Post 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?
Post Reply