CakePHP – Static pages under the root

I’ve recently started using CakePHP, I don’t really understand it too well, but the first thing I noticed was that any static pages you have normally would go under www.site.com/pages. I thought ‘this sucks’, so I’ve made a very simple work-around, which isn’t great, but it seems to work.

The idea is that someone will go to www.site.com/something and then cake will look for the something controller, if it can’t find it, it will normally throw up an error. By altering this error page, we can get cake to do the pages controller action instead of the error one.

So what I did was add the file: views/errors/missing_controller.thtml which contains:

$this->requestAction('pages'.stripslashes($_SERVER['REQUEST_URI']));

That seemed to do it. Not elegant at all, I know, so if you find a nicer way of doing it, or write some nicer code, please give it to me and I’ll post it on here.

Leave a Reply