Apr 072011
 

I’ve begun my journey into the world of Zend Framework, and like a lot of other people out there, I’m clueless. Nevertheless, I am slowly (very slowly, I’ll add) using it to develop my first project.

I’ve already encountered a few problems that I’ve been able to fix. They were very annoying to track down; usually just a single misconfigured setting or incorrectly named file. The upside to this suffering is that I can share the solutions I’ve found with others who might be having the same problems.

Problem

Whenever I browsed to a non-existent page in my application, the ErrorController would not catch the error. Instead, I got a 404 error.

Solution

Set AllowOveride to All in your httpd.conf file.

Explanation

The ErrorController, usually located at application/controllers/ErrorController.php is designed to display errors that your application encounters in a pretty, readable way. By default, it prints out the error message and stack trace, along with some other information. So, why wasn’t I getting this when I browsed to a non-existent page? The solution in my case was quite simple.

The single misconfigured settings, as described in the Solution, wasn’t allowing other .htaccess files to override settings already declared in the httpd.conf file. Zend Tool, the tool I used to create the basic skeleton for my project, had created its own .htaccess file in my public folder. This file contains directives for redirecting every request to the index.php file, where your Zend Framework application is initialized and started. Every request is routed here, no matter the URL. So, visiting http://www.myZendFrameworkSite.site/controller/action really just redirects to that index.php file, with controller/action as the argument.

When I was visiting a non-existent page, the request wasn’t routed to index.php so Zend couldn’t complain that the controller/action didn’t exist. Instead, the browser complained that it couldn’t find the file, which wouldn’t have existed anyway even if the controller/action did.

Credit

Took a while to hunt down the solution. Turned out it was at the top of a Zend Framework tutorial by Rob Allen, here. Thank you Rob!

 

 Posted by at 3:13 pm