Welcome Guest, Not a member yet? Register   Sign In
Extending CodeIgniter’s Exceptions Class
#2

[eluser]packetfox[/eluser]
Hi there,

i have been beating my head against the wall trying to extend the Exception Class; then googling around showed your Website Post which is similar to what i want to do, eg. extending the show_404() (for starters) function so that it will file an entry into a database in addition to logging the error to a file.

Now, no matter what i do, MY_Exceptions.php errors out as soon i do something like $this->CI =& get_instance(); to get the Super Object. After some research, it seems that get_instance() is not available at the time my MY_Exceptions.php calls it. Now i have two questions:

1. How can i load either the Super Object, or at least some additional classes directly from within my extended Exception Class so i can for example access the Database Object?

2. If it does not work for me, how comes it works for you? I mean, sorry if this sounds weird, but for you the Code you posted in your Blog does actually work, and $ci =& get_instance(); does allow you to get to the Superobject, yes?

Thanks and regards!
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

    class MY_Exceptions extends CI_Exceptions {

    function __construct(){
        parent::CI_Exceptions();
// Comment the below out and things will stop working
//$this->CI =& get_instance();
    }

    function show_404($page = '') {    
        $heading = "404 Page Not Found";
        $message = "The ppage you requested was not found.";

        log_message('error', '404 Page Not Found --> '.$page);

// Here is where id like to extend so show_404() will also log to a database        
//$this->custom_logging->log_message('error','System','0',"Requested Page not found: $page");

        echo $this->show_error($heading, $message, 'error_404', 404);
        exit;
    }

    }

?>


Messages In This Thread
Extending CodeIgniter’s Exceptions Class - by El Forum - 02-17-2010, 09:27 AM
Extending CodeIgniter’s Exceptions Class - by El Forum - 04-14-2010, 05:46 AM
Extending CodeIgniter’s Exceptions Class - by El Forum - 04-14-2010, 07:41 AM
Extending CodeIgniter’s Exceptions Class - by El Forum - 04-14-2010, 07:46 AM
Extending CodeIgniter’s Exceptions Class - by El Forum - 04-14-2010, 08:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB