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

[eluser]Aquillyne[/eluser]
[quote author="inparo" date="1212967129"]

MY_Router:
Code:
class MY_Router extends CI_Router {
    
    /* Constructor */
    function MY_Router()
    {
        // Needed for error pages
        session_start();

        parent::CI_Router();
    }
    
    // --------------------------------------------------------------------

    function _validate_request($segments)
    {
        // Check for error flag
        if (isset ($_SESSION['error']) )
        {
            $segments = array('error', 'placebo');

            return $segments;
        }

        parent::_validate_request($segments);
    }
}

MY_Exceptions:
Code:
class MY_Exceptions extends CI_Exceptions {

    var $CI;
    
    /**
     * Controller
     *
     * @access public
     */
    function MY_Exceptions()
    {
        parent::CI_Exceptions();
    }

    // --------------------------------------------------------------------
    
    /**
     * Redirects if the previous request wasn't an error request
     *
     * @access    public
     * @param    mixed    error information
     */
    function _redirect($error)
    {
        $conf    =& load_class('Config');
        $uri    =& load_class('URI');

        // If there is an error in MY_Controller we'll get a loop - stop it
        if (isset ($_SESSION['error']))
        {
            echo '<h2>Fatal Error</h2>';
            echo $_SESSION['error']['message'];
            unset($_SESSION['error']);
            exit;
        }
        $_SESSION['error'] = $error;
        $redirect = $conf->site_url( $uri->uri_string() );
        header("Location: ".$redirect);
    }

    // --------------------------------------------------------------------
    
    /**
     * General Error Page
     *
     * @access    private
     * @param    string    the heading
     * @param    string    the message
     * @param    string    the error function name
     * @return    string
     */
    function show_error($heading = 'Fatal Error', $message = 'Unknown Error', $template = 'error_general')
    {
        $error = array(
            'heading'    => $heading,
            'message'    => $message,
            'template'    => $template
        );
        $this->_redirect($error);
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Native PHP error handler
     *
     * @access    private
     * @param    string    the error severity
     * @param    string    the error string
     * @param    string    the error filepath
     * @param    string    the error line number
     * @return    string
     */
    function show_php_error($severity, $message, $filepath, $line)
    {    
        $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
    
        $filepath = str_replace("\\", "/", $filepath);
        
        // For safety reasons we do not show the full file path
        if (FALSE !== strpos($filepath, '/'))
        {
            $x = explode('/', $filepath);
            $filepath = $x[count($x)-2].'/'.end($x);
        }
        
        $error = array(
            'severity'    => $severity,
            'message'    => $message,
            'filepath'    => $filepath,
            'line'        => $line,
            'template'    => 'error_php'
        );
        
        $this->_redirect($error);
    }
}

[/quote]


Could you explain to me what's actually happening here? I can't follow the logic of it. At what point have you changed it so that errors trigger the error controller?


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