Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming the root controller

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.

like image 769
phillc Avatar asked Apr 24 '09 16:04

phillc


3 Answers

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.

like image 51
Steve Klabnik Avatar answered Nov 17 '22 04:11

Steve Klabnik


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.

like image 6
Gabe Hollombe Avatar answered Nov 17 '22 05:11

Gabe Hollombe


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.

like image 2
zombat Avatar answered Nov 17 '22 03:11

zombat