A Useless “Missing Layout” Error
Cake can be a real bitch with errors. Deciphering exactly what went wrong (and in what file) can take way longer than it should. One such example was a blank Missing Layout error I received last week. Upon firing up one of my Cake apps on my server, the following appeared when visiting a particular page:
Missing Layout: You are seeing this error because the layout file can't be found or doesn't exist.
Notice: If you want to customize this error message, create /cat/views/errors/missing_layout.thtml.
Fatal: Confirm you have created the file :
Now normally, the last line above points you to the file it’s trying to find. This is Cake’s way of pointing you in the right direction – a hint, if you will.
Example: Fatal: Confirm you have created the file : \project\app\views\pages\index.thtml.
Cake’s “hint” to me was blank. CakePHP, eat me.
The weirdest part of this error was that it didn’t exist on my computer. Running my app via localhost worked fine. Running it on my server made it poop, major.
So what was the deal? After way too much digging around, I found that the error didn’t exist in the so-called “missing view”, but instead in the controller file. The controller file being called (which I will call examples_controller.php) had one single, misplaced uppercase character:
class ExamplesController extends AppController {
var $name = 'Examples';
var $helpers = array('Html', 'Form');
var $layout = 'Layout';
...
Notice the $layout variable? It’s case sensitive, buddy. Replacing the uppercase “L” with a lowercase one did the trick:
class ExamplesController extends AppController {
var $name = 'Examples';
var $helpers = array('Html', 'Form');
var $layout = 'layout';
...
No more errors. Lots more happy.
