<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Managing 404 errors in the Zend Framework</title>
	<atom:link href="http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/feed" rel="self" type="application/rss+xml" />
	<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework</link>
	<description>Actionscript/Flex, PHP and Java developer</description>
	<lastBuildDate>Wed, 10 Mar 2010 08:38:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: vlakikosta</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-17425</link>
		<dc:creator>vlakikosta</dc:creator>
		<pubDate>Fri, 29 Jun 2007 23:58:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-17425</guid>
		<description>Tnx for 404 code. I will use it on my web page. :)</description>
		<content:encoded><![CDATA[<p>Tnx for 404 code. I will use it on my web page. <img src='http://www.richardlord.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksey Zapparov A.K.A. iXTi</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-7794</link>
		<dc:creator>Aleksey Zapparov A.K.A. iXTi</dc:creator>
		<pubDate>Wed, 18 Apr 2007 11:58:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-7794</guid>
		<description>For those who do not want any plugins and/or want only to redirect all request to default controller/action when something goes wrong, it can be simply done with one simple line:

$front-&gt;setParam(&#039;useDefaultControllerAlways&#039;, true);

for more info you can refer to manual:

http://framework.zend.com/manual/en/zend.controller.exceptions.html#zend.controller.exceptions.internal</description>
		<content:encoded><![CDATA[<p>For those who do not want any plugins and/or want only to redirect all request to default controller/action when something goes wrong, it can be simply done with one simple line:</p>
<p>$front-&gt;setParam(&#8216;useDefaultControllerAlways&#8217;, true);</p>
<p>for more info you can refer to manual:</p>
<p><a href="http://framework.zend.com/manual/en/zend.controller.exceptions.html#zend.controller.exceptions.internal" rel="nofollow">http://framework.zend.com/manual/en/zend.controller.exceptions.html#zend.controller.exceptions.internal</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksey Zapparov A.K.A. iXTi</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-7773</link>
		<dc:creator>Aleksey Zapparov A.K.A. iXTi</dc:creator>
		<pubDate>Wed, 18 Apr 2007 05:40:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-7773</guid>
		<description>And one more enhancement :)) As you all know abstract Zend_Controller_Action has __call() method which is called if specified action wasn&#039;t found in controller. By default it throws an Exception, but you may redeclare this method in each separate controller. If you don&#039;t understand why you need it, you may read brief explanation on my homepage. So for those who know why you need it, here&#039;s modified version:

require_once &#039;Zend/Controller/Exception.php&#039;;
require_once &#039;Zend/Controller/Plugin/Abstract.php&#039;;

class NoRoute extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$dispatcher = Zend_Controller_Front::getInstance()-&gt;getDispatcher();

try {
/* @var $dispatcher Zend_Controller_Dispatcher_Standard */
$controller_class = $dispatcher-&gt;getControllerClass($request);

// If specified controller is not exists, $dispatcher-&gt;loadClass
// will throw a Zend_Controller_Dispatcher_Exception with message
$controller_name = $dispatcher-&gt;loadClass($controller_class);
$action_name = $dispatcher-&gt;getActionMethod($request);
$controller_obj = new ReflectionClass($controller_name);

// If specified action exists in this controller, then we can
// interrupt plugin and return to normal dispatching mode
if ($controller_obj-&gt;hasMethod($action_name)) {
return;
}

// If specified controller has overrided
$call_overrided_in = $controller_obj-&gt;getMethod(&#039;__call&#039;)
-&gt;getDeclaringClass()
-&gt;getName();
if ($controller_name == $call_overrided_in) {
return;
}

throw new Zend_Controller_Exception();
} catch (Zend_Exception $e) {
// Setting new controller and acton to noroute handler
$request-&gt;setControllerName( &#039;noroute&#039; );
$request-&gt;setActionName( &#039;index&#039; );
// This is very-very internal parametr, that will allow unserialize
// and then use data of exception in noroute handler
$request-&gt;setParam(&#039;__noroute_caught_exception&#039;, serialize($e));
$request-&gt;setDispatched( false );
}

return;
}

As you can notice, this plugin gives you an availability to get the Exception that was caught while plugin worked :)) So in your NorouteController you can call:

$e = unserialize($this-&gt;getRequest()
                               -&gt;getParam(&#039;__noroute_caught_exception&#039;));</description>
		<content:encoded><![CDATA[<p>And one more enhancement <img src='http://www.richardlord.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) As you all know abstract Zend_Controller_Action has __call() method which is called if specified action wasn&#8217;t found in controller. By default it throws an Exception, but you may redeclare this method in each separate controller. If you don&#8217;t understand why you need it, you may read brief explanation on my homepage. So for those who know why you need it, here&#8217;s modified version:</p>
<p>require_once &#8216;Zend/Controller/Exception.php&#8217;;<br />
require_once &#8216;Zend/Controller/Plugin/Abstract.php&#8217;;</p>
<p>class NoRoute extends Zend_Controller_Plugin_Abstract<br />
{<br />
public function preDispatch(Zend_Controller_Request_Abstract $request)<br />
{<br />
$dispatcher = Zend_Controller_Front::getInstance()-&gt;getDispatcher();</p>
<p>try {<br />
/* @var $dispatcher Zend_Controller_Dispatcher_Standard */<br />
$controller_class = $dispatcher-&gt;getControllerClass($request);</p>
<p>// If specified controller is not exists, $dispatcher-&gt;loadClass<br />
// will throw a Zend_Controller_Dispatcher_Exception with message<br />
$controller_name = $dispatcher-&gt;loadClass($controller_class);<br />
$action_name = $dispatcher-&gt;getActionMethod($request);<br />
$controller_obj = new ReflectionClass($controller_name);</p>
<p>// If specified action exists in this controller, then we can<br />
// interrupt plugin and return to normal dispatching mode<br />
if ($controller_obj-&gt;hasMethod($action_name)) {<br />
return;<br />
}</p>
<p>// If specified controller has overrided<br />
$call_overrided_in = $controller_obj-&gt;getMethod(&#8216;__call&#8217;)<br />
-&gt;getDeclaringClass()<br />
-&gt;getName();<br />
if ($controller_name == $call_overrided_in) {<br />
return;<br />
}</p>
<p>throw new Zend_Controller_Exception();<br />
} catch (Zend_Exception $e) {<br />
// Setting new controller and acton to noroute handler<br />
$request-&gt;setControllerName( &#8216;noroute&#8217; );<br />
$request-&gt;setActionName( &#8216;index&#8217; );<br />
// This is very-very internal parametr, that will allow unserialize<br />
// and then use data of exception in noroute handler<br />
$request-&gt;setParam(&#8216;__noroute_caught_exception&#8217;, serialize($e));<br />
$request-&gt;setDispatched( false );<br />
}</p>
<p>return;<br />
}</p>
<p>As you can notice, this plugin gives you an availability to get the Exception that was caught while plugin worked <img src='http://www.richardlord.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) So in your NorouteController you can call:</p>
<p>$e = unserialize($this-&gt;getRequest()<br />
                               -&gt;getParam(&#8216;__noroute_caught_exception&#8217;));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksey Zapparov A.K.A. iXTi</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-7607</link>
		<dc:creator>Aleksey Zapparov A.K.A. iXTi</dc:creator>
		<pubDate>Mon, 16 Apr 2007 08:07:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-7607</guid>
		<description>Excuse me again. I&#039;ve just done full code :)) So your plugin can be like this:

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $dispatcher = Zend_Controller_Front::getInstance()-&gt;getDispatcher();

        try {
            /* @var $dispatcher Zend_Controller_Dispatcher_Standard */
            $controllerClass        = $dispatcher-&gt;getControllerClass($request);
            $controllerclassName    = $dispatcher-&gt;loadClass($controllerClass);
            $actionName             = $dispatcher-&gt;getActionMethod($request);

            $controllerObject       = new ReflectionClass($controllerclassName);
            if ($controllerObject-&gt;hasMethod($actionName)) {
                // Controller and action exists, so we can securely continue
                return;
            }
        } catch (Zend_Exception $e) {
        }

        $request-&gt;setControllerName( &#039;noroute&#039; );
        $request-&gt;setActionName( &#039;index&#039; );
        $request-&gt;setDispatched( false );
    }


And for those who thinking how to make HTTP1.1/Status code, I guess the best solution is to include in NorouteController init() method with setting HTTP Status like this:

class CorouteController extends Zend_Controller_Action
{
    public function init()
    {
        $this-&gt;getResponse()-&gt;setHttpResponseCode(404);
    }

    /* ... skipped ... */
}</description>
		<content:encoded><![CDATA[<p>Excuse me again. I&#8217;ve just done full code <img src='http://www.richardlord.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) So your plugin can be like this:</p>
<p>    public function preDispatch(Zend_Controller_Request_Abstract $request)<br />
    {<br />
        $dispatcher = Zend_Controller_Front::getInstance()-&gt;getDispatcher();</p>
<p>        try {<br />
            /* @var $dispatcher Zend_Controller_Dispatcher_Standard */<br />
            $controllerClass        = $dispatcher-&gt;getControllerClass($request);<br />
            $controllerclassName    = $dispatcher-&gt;loadClass($controllerClass);<br />
            $actionName             = $dispatcher-&gt;getActionMethod($request);</p>
<p>            $controllerObject       = new ReflectionClass($controllerclassName);<br />
            if ($controllerObject-&gt;hasMethod($actionName)) {<br />
                // Controller and action exists, so we can securely continue<br />
                return;<br />
            }<br />
        } catch (Zend_Exception $e) {<br />
        }</p>
<p>        $request-&gt;setControllerName( &#8216;noroute&#8217; );<br />
        $request-&gt;setActionName( &#8216;index&#8217; );<br />
        $request-&gt;setDispatched( false );<br />
    }</p>
<p>And for those who thinking how to make HTTP1.1/Status code, I guess the best solution is to include in NorouteController init() method with setting HTTP Status like this:</p>
<p>class CorouteController extends Zend_Controller_Action<br />
{<br />
    public function init()<br />
    {<br />
        $this-&gt;getResponse()-&gt;setHttpResponseCode(404);<br />
    }</p>
<p>    /* &#8230; skipped &#8230; */<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksey Zapparov A.K.A. iXTi</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-7605</link>
		<dc:creator>Aleksey Zapparov A.K.A. iXTi</dc:creator>
		<pubDate>Mon, 16 Apr 2007 07:30:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-7605</guid>
		<description>Sorry for my chain-post, but just to explain...

$this-&gt;getNorouteControllerName()
and
$this-&gt;getNorouteActionName()

Are used by me to get string &#039;noroute&#039; and &#039;index&#039; :))</description>
		<content:encoded><![CDATA[<p>Sorry for my chain-post, but just to explain&#8230;</p>
<p>$this-&gt;getNorouteControllerName()<br />
and<br />
$this-&gt;getNorouteActionName()</p>
<p>Are used by me to get string &#8216;noroute&#8217; and &#8216;index&#8217; <img src='http://www.richardlord.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksey Zapparov A.K.A. iXTi</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-7604</link>
		<dc:creator>Aleksey Zapparov A.K.A. iXTi</dc:creator>
		<pubDate>Mon, 16 Apr 2007 07:28:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-7604</guid>
		<description>I don&#039;t certainly sure that ZF 0.7 does have such availability, but ZF &gt;= 0.9 does... So this plugin can be simplified like this:

public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $dispatcher = Zend_Controller_Front::getInstance()-&gt;getDispatcher();

        try {
            /* @var $dispatcher Zend_Controller_Dispatcher_Standard */
            $controllerClass    = $dispatcher-&gt;getControllerClass($request);
            $className = $dispatcher-&gt;loadClass($controllerClass);
            /* now you can doo all actions with Reflectioning, like you do */
        } catch (Zend_Exception $e) {
            $request-&gt;setControllerName($this-&gt;getNorouteControllerName());
            $request-&gt;setActionName($this-&gt;getNorouteActionName());
            $request-&gt;setDispatched(false);
        }
    }</description>
		<content:encoded><![CDATA[<p>I don&#8217;t certainly sure that ZF 0.7 does have such availability, but ZF &gt;= 0.9 does&#8230; So this plugin can be simplified like this:</p>
<p>public function preDispatch(Zend_Controller_Request_Abstract $request)<br />
    {<br />
        $dispatcher = Zend_Controller_Front::getInstance()-&gt;getDispatcher();</p>
<p>        try {<br />
            /* @var $dispatcher Zend_Controller_Dispatcher_Standard */<br />
            $controllerClass    = $dispatcher-&gt;getControllerClass($request);<br />
            $className = $dispatcher-&gt;loadClass($controllerClass);<br />
            /* now you can doo all actions with Reflectioning, like you do */<br />
        } catch (Zend_Exception $e) {<br />
            $request-&gt;setControllerName($this-&gt;getNorouteControllerName());<br />
            $request-&gt;setActionName($this-&gt;getNorouteActionName());<br />
            $request-&gt;setDispatched(false);<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SÃ©bastien Cramatte</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-5082</link>
		<dc:creator>SÃ©bastien Cramatte</dc:creator>
		<pubDate>Fri, 23 Mar 2007 13:52:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-5082</guid>
		<description>I&#039;ve resolve the problem ...
You must add this  to your noRoute Method

        $this-&gt;getResponse()-&gt;setHeader(&#039;HTTP/1.1&#039;,&#039;404 Not Found&#039;);
$this-&gt;getResponse()-&gt;setHeader(&#039;Status&#039;,&#039;404 File not found&#039;);</description>
		<content:encoded><![CDATA[<p>I&#8217;ve resolve the problem &#8230;<br />
You must add this  to your noRoute Method</p>
<p>        $this-&gt;getResponse()-&gt;setHeader(&#8216;HTTP/1.1&#8242;,&#8217;404 Not Found&#8217;);<br />
$this-&gt;getResponse()-&gt;setHeader(&#8216;Status&#8217;,'404 File not found&#8217;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SÃ©bastien Cramatte</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-5081</link>
		<dc:creator>SÃ©bastien Cramatte</dc:creator>
		<pubDate>Fri, 23 Mar 2007 13:31:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-5081</guid>
		<description>I try to handle 404 on my Website using  ZF 0.9 !
Works well  with your noRoute  plugin. Unfortunately 
I don&#039;t how can retur correct  Status ? 

Google Sitemap check if really  site can handle 404 properly... using mod_rewrite  seems that Apache won&#039;t return  correct status code ?

I&#039;ve tried this in my  noRoute method 

$this-&gt;getResponse()-&gt;setHeader(&#039;Status&#039;,&#039;404 File not found&#039;);

But doen&#039;t work as expected ...

Any tips, ideas, solutions ... ?

Regards</description>
		<content:encoded><![CDATA[<p>I try to handle 404 on my Website using  ZF 0.9 !<br />
Works well  with your noRoute  plugin. Unfortunately<br />
I don&#8217;t how can retur correct  Status ? </p>
<p>Google Sitemap check if really  site can handle 404 properly&#8230; using mod_rewrite  seems that Apache won&#8217;t return  correct status code ?</p>
<p>I&#8217;ve tried this in my  noRoute method </p>
<p>$this-&gt;getResponse()-&gt;setHeader(&#8216;Status&#8217;,'404 File not found&#8217;);</p>
<p>But doen&#8217;t work as expected &#8230;</p>
<p>Any tips, ideas, solutions &#8230; ?</p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-3900</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Thu, 08 Mar 2007 23:40:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-3900</guid>
		<description>Thank you for the code, it does really what I need.

Sincerely,
Alexander</description>
		<content:encoded><![CDATA[<p>Thank you for the code, it does really what I need.</p>
<p>Sincerely,<br />
Alexander</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dave</title>
		<link>http://www.richardlord.net/blog/managing-404-errors-in-the-zend-framework/comment-page-1#comment-2916</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Tue, 20 Feb 2007 10:23:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/managing-404-errors-in-the-zend-framework/#comment-2916</guid>
		<description>ahh yes, no route/controller
i might have to steal your code for that :D</description>
		<content:encoded><![CDATA[<p>ahh yes, no route/controller<br />
i might have to steal your code for that <img src='http://www.richardlord.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
