Easier Static Pages for CakePHP 1.2

February 5th, 2008  |  Published in CakePHP  |  1 Comment

Easier Static Pages for CakePHP 1.2

>Traditionally in a CakePHP application, to do static pages you have two options:

  1. Use the built-in Pages controller and either have all static pages reside in /pages/pagename or set up custom routes.
  2. Set up an empty action in a controller.

I didn’t like either of those options.

So what with Nate’s help J. Snook makes a custom ErrorHandler to handle the missing controller actions and gets it to look for views in the /views/controllers folder that match and renders them otherwise it does the normal error thing that cake does. I’m working on an extension to this to replace the default route method that I used to serve items from my ContentsController. I’ll keep you informed of the progress but check out. So my plan will to do a quick check in here for things in Contents that might match the path first (or in the cache ;-) ) some small corrections, thanks to JS

(Via snook.ca - a collection of tips, tricks and bookmarks in web development.)

Responses

  1. Jonathan Snook says:

    February 5th, 2008 at 9:10 pm (#)

    Just to clarify, it doesn’t look in the /view/pages but rather in the /view/controllername/ where controllername matches the first URL segment (which is usually auto-routed to a controller).

Leave a Response