Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make custom error pages in cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.93k
    Comment on it

    Hello Readers ,

    If any one enters the wrong URL then how to show our custom error page , follow the below code.

    Exception render need to set as an AppExceptionRender.

    /app/Config/core.php

    Configure::write('Exception', array(
            'handler' => 'ErrorHandler::handleException',
            'renderer' => 'AppExceptionRenderer',
            'log' => true
    ));
    

    /app/Controller/ErrorsController.php

    class ErrorsController extends AppController {
        public $name = 'Errors';
    
        public function beforeFilter() {
            parent::beforeFilter();
            $this->Auth->allow('error404');
        }
    
        public function error404() {
            //$this->layout = 'default';
        }
    }
    

    /app/Lib/Error/AppExceptionRenderer.php

    App::uses('ExceptionRenderer', 'Error');
    
        class AppExceptionRenderer extends ExceptionRenderer {
    
            public function notFound($error) {
                $this->controller->redirect(array('controller' => 'errors', 'action' => 'error404'));
            }
        }
    

    /app/View/Errors/error404.ctp

    <div class="inner404">
        <h2>404 Error - Page Not Found</h2>
    </div>
    

    Hoping this will help you.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: