Welcome Guest, Not a member yet? Register   Sign In
How to load a view for the error page?
#7

[eluser]Pascal Kriete[/eluser]
And now we need an error controller and error views. I'll just do the controller.

Error Controller:
Code:
class Error extends Controller {

    /**
     * Constructor
     *
     * @access    public
     */
    function Error()
    {
        parent::Controller();
    }

    // --------------------------------------------------------------------

    /**
     * Shows error pages depending on the type of error
     *
     * @access    private
     */
    function _remap()
    {
        $err = $_SESSION['error'];
        unset($_SESSION['error']);

        switch($err['template'])
        {
            case 'error_404':
                $this->_error_404($err['heading'], $err['message']);
                break;
            case 'error_php':
                $this->_error_php($err['severity'], $err['message'], $err['filepath'], $err['line']);
                break;
            case 'error_db':
                $this->_error_db($err['heading'], $err['message']);
                break;
            case 'error_general':
            default:
                $this->_error_general($err['heading'], $err['message']);
        }
        
    }

    // --------------------------------------------------------------------

    /**
     * Display General Errors
     *
     * @access    private
     * @param    string    heading
     * @param    string    error message
     * @return    description
     */
    function _error_general($heading, $message)
    {
        $data = array(
            'heading' => $heading,
            'message' => $message
        );
        
        $this->load->view('error/general', $data);
    }

    // --------------------------------------------------------------------
    
    /**
     * Display 404 Errors
     *
     * @access    private
     * @param    string    heading
     * @param    string    error message
     */
    function _error_404($heading, $message)
    {
        header("HTTP/1.1 404 Not Found");

        $data = array(
            'heading' => $heading,
            'message' => $message
        );

        $this->load->view('error/404', $data);
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Display PHP Errors
     *
     * @access    private
     * @param    string    severity
     * @param    string    message
     * @param    string    filepath
     * @param    integer    line
     */
    function _error_php($severity, $message, $filepath, $line)
    {
        $data = array(
            'severity'    => $severity,
            'message'    => $message,
            'filepath'    => $filepath,
            'line'        => $line,
            'template'    => 'error_php'
        );

        $this->load->view('error/php', $data);
    }

    // --------------------------------------------------------------------

    /**
     * Display Database Errors
     *
     * @access    private
     * @param    string    heading
     * @param    string    error message
     * @return    description
     */
    function _error_db($heading, $message)
    {
        $data = array(
            'heading' => $heading,
            'message' => $message
        );

        $this->load->view('error/db', $data);
    }
    
}

I had to copy paste that together with a few changes, so hopefully it works. Be careful when using this with a MY_Controller class, it loops easily.


Messages In This Thread
How to load a view for the error page? - by El Forum - 06-07-2008, 08:57 PM
How to load a view for the error page? - by El Forum - 06-08-2008, 04:07 AM
How to load a view for the error page? - by El Forum - 06-08-2008, 07:04 AM
How to load a view for the error page? - by El Forum - 06-08-2008, 07:43 AM
How to load a view for the error page? - by El Forum - 06-08-2008, 11:28 AM
How to load a view for the error page? - by El Forum - 06-08-2008, 12:18 PM
How to load a view for the error page? - by El Forum - 06-08-2008, 12:21 PM
How to load a view for the error page? - by El Forum - 07-19-2008, 12:32 PM
How to load a view for the error page? - by El Forum - 07-19-2008, 01:48 PM
How to load a view for the error page? - by El Forum - 07-19-2008, 03:04 PM
How to load a view for the error page? - by El Forum - 07-19-2008, 03:25 PM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:16 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:23 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:28 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:30 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:31 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:33 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:42 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:44 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 10:58 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 11:09 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 11:12 AM
How to load a view for the error page? - by El Forum - 07-20-2008, 12:21 PM
How to load a view for the error page? - by El Forum - 07-20-2008, 01:11 PM
How to load a view for the error page? - by El Forum - 07-20-2008, 01:15 PM
How to load a view for the error page? - by El Forum - 07-20-2008, 05:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB