views:

99

answers:

4

Where do you guys put your static pages, like "home", in an MVC framework? Do you have a "home" controller? A "pages" controller? Do you create actions for each static page?

I'm using CFWheels now, and I'm trying to figure out the best place to put them.


Edit: Apparently CFWheels doesn't require you to create actions for all your views. So you can just create an empty controller and call the views like actions, but not have to write out the blank functions.

+2  A: 

CakePHP (and I guess, Ruby On Rails) has a "pages" controller. There is a routing function which redirects requests to /pages/foo to /pages/display/foo. Similarly, / is redirected to /pages/display/home. The display action looks up the views/pages folder for any file with a matching name and renders that.

nickf
+1  A: 

I put my static pages in the database using a simple CMS with a private admin page.

This way, the clients can make simple changes themselves.

SLaks
+1  A: 

At the end of the day, a static page is a view without a model, that was returned based on an action the user requested from your server by hitting particular route. :-)

Yes, technically you could expose the direct location of the view resource to the user and rely on the http daemon to go fetch it and return it. However, that means that the resource URL is now tied not to the semantic of the resource you want to expose, but to actual bits. This means that if you want another representation of that same resource, you have to expose it on a different URL.

So, when you create the structure of your web app, think first about the URLs and the resources you want to expose and then think how to implement each resource.

Franci Penov
If you were commenting on what I said about CF Wheels, I worded it poorly. It doesn't call the files directly, and you can still route them, you just don't have to have pointless empty functions for each view :)
Mark
+1  A: 

In Wheels, you don't even need to create the controller file.

If you create your view here: views/about/index.cfm

You don't need to create the controller file at all. Then you should be able to just call this with no problems: http://www.example.com/about

Chris Peters
Ah... while that's nice, I think you're abusing index files ;)
Mark
Hey, it works if you need to then add views/about/executives.cfm and views/about/contact.cfm or whatever. Then you can access www.example.com/about/executives and www.example.com/about/contact, etc.Or was there something about your joke that I wasn't getting? haha
Chris Peters
My point was I don't think you should have a folder with a single file in it for each static page. But if you're going to throw other stuff in there, then sure.
Mark