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 7404779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:18:17+00:00 2026-05-29T05:18:17+00:00

I tried to follow the instructions here: http://kohanaframework.org/3.0/guide/kohana/tutorials/error-pages But for some reason I am

  • 0

I tried to follow the instructions here: http://kohanaframework.org/3.0/guide/kohana/tutorials/error-pages But for some reason I am unable to catch the HTTP_Exception_404 I still get a ugly error page and not my custom page.

Also when I type in the URL error/404/Message, I get a ugly Kohana HTTP 404 error message.

Here is the files structure:

  • modules
    • my
      • init.php
      • classes
        • controller
          • error_handler.php
        • http_response_exception.php
        • kohana.php
      • views
        • 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

I really cannot see where I have done wrong. Thanks in advance for any help.

  • 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-05-29T05:18:18+00:00Added an answer on May 29, 2026 at 5:18 am

    After a VERY LONG TIME of searching I finally found a solution to my little problem.

    Here is a step by step tutorial on how to load your own custom error pages with Kohana 3.2:

    1. Change the environment variable in the bootstrap.

    Here you have multiple options:

    a. Do what they say in the documentation of the bootstrap.php:

    /**
     * Set the environment status by the domain.
     */
    
    if (strpos($_SERVER['HTTP_HOST'], 'kohanaphp.com') !== FALSE)
    {
        // We are live!
        Kohana::$environment = Kohana::PRODUCTION;
    
        // Turn off notices and strict errors
        error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
    }
    

    b. Or just add those two lines without the “if”:

    Kohana::$environment = Kohana::PRODUCTION;
    error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
    

    c. I have not try this way but in the new bootstrap.php you have this code:

    /**
     * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
     *
     * Note: If you supply an invalid environment name, a PHP warning will be thrown
     * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
     */
    if (isset($_SERVER['KOHANA_ENV']))
    {
        Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
    }
    

    I assume that you could just give the value “production” to “$_SERVER[‘KOHANA_ENV’]” before those lines.

    Again, like I said I haven’t tried it, but it should work.

    I personally just commented out those lines of codes.

    2 Now you need to add a few configurations in a “ini.php” file, or in the “bootstra.php” file.

    <?php defined('SYSPATH') or die('No direct script access.');
    
    /**
     * Turn errors into exceptions. 
     */
    Kohana::$errors = true;
    
    /**
     * Custom exception handler.
     */
    restore_exception_handler();
    set_exception_handler(array('Exception_Handler', 'handler'));
    
    /**
     * Error route.
     */
    Route::set('error', 'error/<action>(/<message>)', array('action' => '[0-9]++', 'message' => '.+'))
    ->defaults(array(
        'controller' => 'exception_handler'
    ));
    

    This is what was missing and made it to hard. For the rest you can easily just follow Kohana3.2 documentation or you can get the module that I added to a repo in GitHub: https://github.com/jnbdz/Kohana-error

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

Sidebar

Related Questions

I have tried to follow the instructions here http://docs.oracle.com/cd/B31017_01/web.1013/b28221/cmp30cfg001.htm Along with using generic model.
I tried to follow the instruction describe here: http://docs.oracle.com/javafx/2.0/webview/jfxpub-webview.htm to display a web page
I tried to follow many online tutorials to run kmeans example present in Mahout.
I tried to follow this but the default modelbinder let my array null on
I'm trying to follow the instructions here to run my Grails build on the
I'm trying to follow the instructions on the Dropbox developer's site, but I can't
I tried to follow these instructions get OpenCV to compile on my MAC MINI,
I have tried to follow the instructions in Installing and Configuring Web Deploy for
I tried to follow this instruction to setup UITableView programatically, but the height of
I'm looking to use jScrollPane's scrollToElement API function here: http://dextersgospel.com/index-test.html Instructions on it's usage

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.