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).
This post was written by Brad Garrett on May 21, 2009. You can read more from Brad's blog or learn more about Brad. If you'd like to follow Merge's blog, please subscribe to the RSS Feed. To hear more about these posts, you can also follow @merge on Twitter.
Popular Posts
- Dashboards: Cool tools or sensory overload?
- Web Design Trends for 2012
- Dashboards: Cool Tools or Sensory Overload
- Introducing Buffalo Battles, Merge’s own FedEx days / 20 Percent Time
- Higher Education Search Marketing
- The Death of Print Media?
- You Only Have One Shot at Making a Web Impression
- 10 Things We Are Thankful for This Year
- Apples to Crapples
- Mobile Trends for 2012

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