CakePHP and Error Page Issues

All right, let's get technical. Here at Merge HQ we use a top-notch framework called CakePHP to build some of our custom applications, but recently I encountered a mystifying issue whilst hacking away on a big project. Cake seems to have an odd habit of ignoring some of your code when it generates error pages (you know, those lovely 404 "file not found" pages we all cherish). In my case, the title of the site and the main menu refused to display, so that's a bit jarring, to say the least.

Fortunately, after a day of sifting through more CakePHP code than I'd prefer, I happened upon a solution. This is a problem that has plagued plenty of developers besides me, and I can only hope they might benefit as well. So what's the scoop? The short version is simply to add the following code to your app_controller.php file:

function __construct() {
parent::__construct();
if ($this->name == 'CakeError') {
$this->constructClasses();
$this->beforeFilter();
}
}

This forces Cake to load the components your site uses and run the normal setup code on your site's error pages. The long version of this solution can be read (or fallen asleep to) on my blog. Let it never be said the life of a web developer is just all cherries and ice cream (although admittedly there is an ample supply of both).

Comments

Lifesaver!

Unbelievable how hidden and undocumented this specific case it. I spent a few hours on this last night and got nowhere. I copy/pasted your code in and it just works. Thanks a million!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Recent Blog Posts

Press Releases

Up

August 2, 2010
GREENVILLE, S.C. – August 02, 2010 Merge, an Upstate web-marketing firm that provides “web excellence” through strategic solutions, recently...
July 19, 2010
GREENVILLE, S.C. – July 19, 2010 Bonitz, one of the nation’s largest commercial flooring companies, has retained Merge to develop and implement an...
July 16, 2010
GREENVILLE, S.C. – July 16, 2010 Award-wining architecture and interior design firm, McMillan Pazdan Smith, has retained Merge to create and deliver...
July 2, 2010
GREENVILLE, S.C. – July 2, 2010CDS, an organization whose vision is to ensure that individuals with developmental needs and their families reach...