I
I
Ivan Trofimov2012-11-09 21:25:41
Kohana
Ivan Trofimov, 2012-11-09 21:25:41

Exception handling in Kohana 3.3 (404 error)?

Hello. Has anyone experienced creating their own 404 error page on Kohana 3.3. If there are, please respond. I can't figure out how exactly to get the status of the request, and if it is != 200, then display the corresponding error page to the user (403, 404, etc.).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PomanoB, 2012-11-09
@cbone

Isn't it? - kohanaframework.org/3.3/guide/kohana/tutorials/error-pages
In 3.3 they made it great, you don't have to check anything, just override the HTTP_Exception_404 class, in which all the logic is implemented in the get_response method

class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
 
    /**
     * Generate a Response for the 404 Exception.
     *
     * The user should be shown a nice 404 page.
     * 
     * @return Response
     */
    public function get_response()
    {
        $view = View::factory('errors/404');
 
        // Remembering that `$this` is an instance of HTTP_Exception_404
        $view->message = $this->getMessage();
 
        $response = Response::factory()
            ->status(404)
            ->body($view->render());
 
        return $response;
    }
}

N
NeX, 2012-11-10
@NeX

Another feature of version 3.3. In case the uri is not found in the route, Request::factory()->execute() will return HTTP_Exception_404 instead of throwing it. See Request->execute() sources

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question