Question

I've been trying to find a full explanation on how to custom error pages in Kohana 3.0 and I haven't been lucky so far. So, based on the solution provided by Kohana Guide can anyone show me how to do it?

When I say full explanation I mean, the location of the classes, their names, which ones to extend, full code, and please, a view for one of the errors.

Many thanks.

Was it helpful?

Solution

I suggest you read http://kohanaframework.org/3.0/guide/kohana/conventions. You can work out the files that need to be created for yourself based on the class names and how Kohana autoloads. The beauty of Kohana for me is that it doesn't try and do everything for you and for that reason its is really important to read the documentation in my opinion.

Note: I haven't used Kohana 3.0 in particular but this should apply.

For example, in part 1, is this code:

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

class HTTP_Response_Exception extends Kohana_Exception {}

Kohana uses a 'cascading filesystem' so you would add the code shown in 2 to

application/classes/kohana/exception.php

Inside that file you would extend the Kohana exception handler

class Kohana_Exception extends Kohana_Kohana_Exception {

   public static function exception_handler(Exception $e)
   {
       ...
   }
}

The route shown gets added to your applications bootstrap which is under

application/bootstrap.php

As errors are being routed you can tell what the controller will be:

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

So there will be a controller created at:

application/classes/controller/error_handler.php

This will look like:

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

class Controller_Error_Handler extends Controller_Template {

    ...

    public function action_404()
    {
        $this->template->title = '404 Not Found';
        // A view example
        $view = View::factory('error/404');
        $view->render();
        ...
    }
}

Your views would then (possibly) be placed under:

application/views/error/404.php

The reason the documentation is brief is because the same answers do not apply to everyone. For example the majority of people (I know) use their own templates etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top