Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I catch a HTTP_Exception_404 Error in Kohana
    text
    copied!<p>I tried to follow the instructions here: <a href="http://kohanaframework.org/3.0/guide/kohana/tutorials/error-pages" rel="nofollow">http://kohanaframework.org/3.0/guide/kohana/tutorials/error-pages</a> But for some reason I am unable to catch the HTTP_Exception_404 I still get a ugly error page and not my custom page.</p> <p>Also when I type in the URL error/404/Message, I get a ugly Kohana HTTP 404 error message.</p> <p>Here is the files structure:</p> <ul> <li>modules <ul> <li>my <ul> <li>init.php</li> <li>classes <ul> <li>controller <ul> <li>error_handler.php</li> </ul></li> <li>http_response_exception.php</li> <li>kohana.php</li> </ul></li> <li>views <ul> <li>error.php</li> </ul></li> </ul></li> </ul></li> </ul> <p>Code:</p> <p>init.php:</p> <pre><code>&lt;?php defined('SYSPATH') or die('No direct access'); Route::set('error', 'error/&lt;action&gt;(/&lt;message&gt;)', array('action' =&gt; '[0-9]++', 'message' =&gt; '.+')) -&gt;defaults(array( 'controller' =&gt; 'error_handler' )); </code></pre> <p>http_response_exception.php:</p> <pre><code>&lt;?php defined('SYSPATH') or die('No direct access'); class HTTP_Response_Exception extends Kohana_Exception { public static function exception_handler(Exception $e) { if (Kohana::DEVELOPMENT === Kohana::$environment) { Kohana_Core::exception_handler($e); } else { Kohana::$log-&gt;add(Kohana::ERROR, Kohana::exception_text($e)); $attributes = array ( 'action' =&gt; 500, 'message' =&gt; rawurlencode($e-&gt;getMessage()), ); if ($e instanceof HTTP_Response_Exception) { $attributes['action'] = $e-&gt;getCode(); } // Error sub-request. echo Request::factory(Route::url('error', $attributes)) -&gt;execute() -&gt;send_headers() -&gt;response; } } } </code></pre> <p>kohana.php:</p> <pre><code>&lt;?php defined('SYSPATH') or die('No direct script access.'); class Kohana extends Kohana_Core { /** * Redirect to custom exception_handler */ public static function exception_handler(Exception $e) { Error::exception_handler($e); } } // End of Kohana </code></pre> <p>error_handler.php:</p> <pre><code>&lt;?php defined('SYSPATH') or die('No direct access'); class Controller_Error_handler extends Controller { public function before() { parent::before(); $this-&gt;template = View::factory('template/useradmin'); $this-&gt;template-&gt;content = View::factory('error'); $this-&gt;template-&gt;page = URL::site(rawurldecode(Request::$instance-&gt;uri)); // Internal request only! if (Request::$instance !== Request::$current) { if ($message = rawurldecode($this-&gt;request-&gt;param('message'))) { $this-&gt;template-&gt;message = $message; } } else { $this-&gt;request-&gt;action = 404; } } public function action_404() { $this-&gt;template-&gt;title = '404 Not Found'; // Here we check to see if a 404 came from our website. This allows the // webmaster to find broken links and update them in a shorter amount of time. if (isset ($_SERVER['HTTP_REFERER']) AND strstr($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME']) !== FALSE) { // Set a local flag so we can display different messages in our template. $this-&gt;template-&gt;local = TRUE; } // HTTP Status code. $this-&gt;request-&gt;status = 404; } public function action_503() { $this-&gt;template-&gt;title = 'Maintenance Mode'; $this-&gt;request-&gt;status = 503; } public function action_500() { $this-&gt;template-&gt;title = 'Internal Server Error'; $this-&gt;request-&gt;status = 500; } } // End of Error_handler </code></pre> <p>I really cannot see where I have done wrong. Thanks in advance for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload