Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8310163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:21:38+00:00 2026-06-08T19:21:38+00:00

I am trying to make custom error pages for 404, 403, 5xx errors. I

  • 0

I am trying to make custom error pages for 404, 403, 5xx errors. I followed the doc and created an error controller, override Kohana_Exception class and added a route.

Kohana_Exception Class

class Kohana_Exception extends Kohana_Kohana_Exception {
    public static function handler(Exception $e) {
        if (Kohana::DEVELOPMENT === Kohana::$environment) {
            parent::handler($e);
        } else {
            try {
                Kohana::$log->add(Log::ERROR, parent::text($e));
                $attributes = array('action' => 500, 'message' => rawurlencode($e->getMessage()));
                if ($e instanceof HTTP_Exception) {
                    $attributes['action'] = $e->getCode();
                }
                // Error sub-request.
                echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body();
            }
            catch(Exception $e) {
                // Clean the output buffer if one exists
                ob_get_level() and ob_clean();
                // Display the exception text
                echo parent::text($e);
                // Exit with an error status
                exit(1);
            }
        }
    }
}

Error Controller

<?php defined('SYSPATH') OR die('No direct access allowed.');
class Controller_Error extends Webim_Template {
    public function before() {
        parent::before();
        $this->template->page = URL::site(rawurldecode(Request::$initial->uri()));
        // Internal request only!
        if (Request::$initial !== Request::$current) {
            if ($message = rawurldecode($this->request->param('message'))) {
                $this->template->message = $message;
            }
        } else {
            $this->request->action(404);
        }
        $this->response->status((int)$this->request->action());
    }
    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->response->status(404);
    }
    public function action_403() {
        $this->request->redirect('welcome');
    }
    public function action_503() {
        $this->template->title = __('Maintenance Mode');
    }
    public function action_500() {
        $this->template->title = __('Internal Server Error');
    }
}

Route

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

Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(array(
        'controller' => 'welcome',
        'action'     => 'index',
    ));

When I throw an HTTP_Exception_403 exception It does not redirect to welcome as it should according to the error controller. I think I am missing very simple thing here.

I debugged it and found execution point is not reaching to my controller. So it might be a problem in Route. What would be the proper route? what could be the real problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:21:39+00:00Added an answer on June 8, 2026 at 7:21 pm

    Your error routes to the Controller_Error_Handler, but your controller is called Controller_Error.

    In case this will be a problem: Kohana expects a Controller_Error_Handler class in classes/error/handler.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a custom HTTP 404 error page when someone types
I am trying to add custom error pages to my web application. So far
I have been trying to make custom radio buttons using HTML, CSS, and JavaScript.
I am trying to make Custom RelativeLayout which can scale and scroll. Right now
Trying to make a custom :confirm message for a rails form that returns data
I´m trying to make a custom component to javafx, so I make my class
Im trying to make my custom TTreeNode Class for example TCustomTreeNode = class(TTreeNode) private
I'm trying to make a custom tabgroup in appcelerator in which one (or two)
I'm trying to make a custom view in Django admin. I'm reading from this
I'm trying to make a custom infowindow. Version = 2. I have added my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.