These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Custom error handling in 3.3
  • I understand the examples as documented here, but I can't figure out how to hand off exceptions to a controller so that I can display error messages within my usual template view. Any suggestions welcome.

  • Moshe Katz's bug report seems to address this issue, but there is no comment from the devs as yet. Not sure about your example though, Moshe. I wouldn't be throwing a 404 exception "if the requested product ID is not found in the database", but then we're all different. :-)

  • I've done this way, would appreciate any corrections.

    Controller_Error:

    <?php defined('SYSPATH') or die('No direct script access.');
    
    class Controller_Error extends Controller_Template_Website {
    
        public function action_404()
        {
            $this->template->title = '404';
    
            $this->template->content = View::factory('errors/404');
        } // End action_404
    
    } // End Controller_Error
    

    HTTP_Exception_404

    <?php defined('SYSPATH') or die('No direct script access.');
    
    class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
    
            // Error sub request
            $request =  Request::factory(Route::get('error')->uri(array('action' => '404')))
                ->execute()
                ->send_headers()
                ->body();
            
            $response = Response::factory()
                 ->status(404)
                 ->body($request);
     
            return $response;
    
    } // End HTTP_Exception_404
    
  • @nazarov: thank you; but I would prefer to bypass the individual HTTP_Exception classes. I'll have another go at over-riding the new Exception class.

  • Incidentally, several other issues have been raised which all seem to point to the same basic problem, but I can't find a definitive response from the devs. I'm going to stick to 3.2 until this is sorted out.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion