Wie fange ich eine HTTP_Exception_404 Fehler in Kohana

Ich habe versucht, Folgen den Anweisungen hier: http://kohanaframework.org/3.0/guide/kohana/tutorials/error-pages Aber aus irgendeinem Grund bin ich nicht in der Lage zu fangen die HTTP_Exception_404 bekomme ich noch einen hässlichen Fehler-Seite und nicht meine eigene Seite.

Auch geben, wenn ich in die URL-Fehler/404/Nachricht, bekomme ich eine hässliche Kohana HTTP 404-Fehlermeldung.

Hier ist die Dateien-Struktur:

  • Module
    • meine
      • init.php
      • Klassen
        • controller
          • error_handler.php
        • http_response_exception.php
        • kohana.php
      • Ansichten
        • error.php

Code:

init.php:

<?php defined('SYSPATH') or die('No direct access');

Route::set('error', 'error/<action>(/<message>)', array('action' => '[0-9]++', 'message' => '.+'))
    ->defaults(array(
            'controller' => 'error_handler'
));

http_response_exception.php:

<?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->add(Kohana::ERROR, Kohana::exception_text($e));

                    $attributes = array
                    (
                            'action'  => 500,
                            'message' => rawurlencode($e->getMessage()),
                    );

                    if ($e instanceof HTTP_Response_Exception)
                    {
                            $attributes['action'] = $e->getCode();
                    }

                    //Error sub-request.
                    echo Request::factory(Route::url('error', $attributes))
                            ->execute()
                            ->send_headers()
                            ->response;
            }
    }
}

kohana.php:

<?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

error_handler.php:

<?php defined('SYSPATH') or die('No direct access');

class Controller_Error_handler extends Controller {

    public function  before()
    {
            parent::before();

            $this->template = View::factory('template/useradmin');
            $this->template->content = View::factory('error');

            $this->template->page = URL::site(rawurldecode(Request::$instance->uri));

            //Internal request only!
            if (Request::$instance !== Request::$current)
            {
                    if ($message = rawurldecode($this->request->param('message')))
                    {
                            $this->template->message = $message;
                    }
            }
            else
            {
                    $this->request->action = 404;
            }
    }

    public function action_404()
    {
            $this->template->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->template->local = TRUE;
            }

            //HTTP Status code.
            $this->request->status = 404;
    }

    public function action_503()
    {
            $this->template->title = 'Maintenance Mode';
            $this->request->status = 503;
    }

    public function action_500()
    {
            $this->template->title = 'Internal Server Error';
            $this->request->status = 500;
    }

} //End of Error_handler

Kann ich wirklich nicht sehen, wo ich falsch gemacht habe. Vielen Dank im Voraus für jede Hilfe.

InformationsquelleAutor jnbdz | 2011-09-16
Schreibe einen Kommentar