views:

231

answers:

4

I am always trumped by this question when starting a new project. When I look at examples like Mephisto, Typo, etc. they route their root to a controller that relates to a specific resource/model.

My problem is, almost every website I've ever built, I feel like my front page is actually a collaboration of all my models, and I can't see myself pointing to a controller that is related to a specific one as my landing page.

Does anyone tend to create a controller that is specifically intended for the front of the website? Or if maybe I am looking at this entirely wrong, please let me know.

edit:

Here is where my confusion exists:

rboard's routes maps root to a controller named index... but i can't even find an index controller

mephisto's routes use some custom routing thing, and there is no root or even a map.connect to '/'

radiant's routes for the bulk of the app goes to one controller, which then does some crazy magic

track's routes go to a controller that is related to a resource (this is an example closest to what i described above)... but doesnt fit me because as i said, my roots tend to have tons of things.

spot us actually does something similar to what i do, have a home controller that just has a show actions, and that is my front page.

+2  A: 

Not sure if this is the answer you're looking for, but here's what I do. I usually use a combination of two controller types, a Front Controller and Action controllers. The Front Controller takes care of URL routing and determining what action to take, while the Action Controllers provide the actual functionality. It's a similar approach to what Zend Framework does.

With that being said, I'll pipe all traffic through a Front Controller, including front page traffic. I usually have an action controller named "IndexController" that handles miscellaneous page requests, and often the front page falls under that category (as well as things like privacy policy pages, contact forms, etc).

If a page is not specifically related to any of the business domain logic of the site, I tend to put it under my Index action controller, although I strive to group site functionality as best as possible.

zombat
+3  A: 

Does anyone tend to create a controller that is specifically intended for the front of the website? Or if maybe I am looking at this entirely wrong, please let me know.

The short answer is "yes".

For what it's worth, I usually take a similar approach to Spot.Us and define a HomeController with an index action/view and just leave it at that.

Gabe Hollombe
I go with HomeController. Home, Default, Site all seem good to me.
spilth
A: 

SiteController seems like the best name to me. SiteController will contain your most important action, index, and my SiteController always contains other actions like contact, about, etc.

David
+3  A: 

My problem is, almost every website I've ever built, I feel like my front page is actually a collaboration of all my models, and I can't see myself pointing to a controller that is related to a specific one as my landing page.

Exactly. So what you're doing is correct.

I often make two controllers for interactions with things that aren't the usual REST stuff: 'welcome' and 'dashboard.' The welcome controller is mapped to my site's root, and the 'dashboard' controller is similar, but for logged in users.

Steve Klabnik
So what you're saying is that most people's home page is essentially one restful resource, where this situation warrants a special case to not map to a controller that relates to a model.
phillc
I don't know about most people's. Mine are usually like yours. They're not a resouce, they're a bunch of different ones.
Steve Klabnik