Documentation


SEARCH

TABLE OF CONTENT

    1. Getting started 2. Basic concepts 3. Request dispatching 4. Context container 5. Dual MVC 6. Component model: 7. Security 8. Configuration 9. Session handling 10. I18n 11. Cache 12. Logging 13. Error handling 14. Advanced Topics 15. API reference

      Tutorials: Frequently Asqued Questions

      See also:


      The Error Page

      Customizing how errors are shown

      Table of Contents

      The default error page

      When an unhandled exception occurs, Lion shows the exception message as well as the trace and some other extra information in a page as following

      This page shows the type of exceptions (i.e. Internal core error), the error code (i.e. 55712), the error message (i.e. Unable to resolve a controller for code: hello).
      It also shows the complete trace, which allow to expand the excerpt of code of each call within the execution stack

      Customizing the error page

      Lion delegates in a class, the Error Printer, to render and output the error page. However, Lion allow to customize that page as well as the content that is shown to the user

      To do that, we have to change the ERROR_PRINTER setting to point to our own class within the app/config/application.ini

      1. ...
      2.  
      3. ;----------------------------------------------------
      4. ;CUSTOM ERROR PRINTER CLASSES:
      5. ;----------------------------------------------------
      6. HTTP_ERROR_PRINTER_CLASS          "MyOwnErrorPrinter"
      7. ;COMMAND_LINE_ERROR_PRINTER_CLASS ""
      8. ;XMLHTTP_ERROR_PRINTER_CLASS      ""
      9.  
      10. ...

      The error printer is a class implementing the __IErrorPrinter interface, which includes to create a method __IErrorPrinter::displayError() that is call when an unhandled exceptions is raised to.

      We can use the MVC, as we're doing to render other pages, to output this page.
      i.e.

      1. <?php
      2.  
      3. class MyOwnErrorPrinter implements __IErrorPrinter {
      4.  
      5.     public function displayError(Exception $exception{
      6.         $request $this->_getRequest($exception);
      7.         $action_identity new __ActionIdentity('yourOwnErrorControllerCodeHere');
      8.         $response __FrontController::getInstance()->getResponse();
      9.         if($response != null{
      10.             $response->clear()
      11.             $response __ActionDispatcher::getInstance()->dispatch($action_identity$request$response);
      12.             $response->flushAll();
      13.         }
      14.         else {
      15.             print "Unknown Error";
      16.         }
      17.         exit;
      18.     }
      19.     
      20. }

      So we can design our own controller and view to render our exceptions and errors.
      i.e. Look the difference between the same error shown by the default error printer, and by a customized error printer:

      The first page shows how the error is shown by a customized error printer. The second screenshot shows the same error rendered by the default error printer class.