I can't extend the Exceptions class .

#1
[eluser]Twisted1919[/eluser]
Hi there , i don't know if i'm doing this in the right way , but here is my situation .
I have MY_Controller , which in its constructor checks if the site is online or under maintenance , as follows :
Code:
class MY_Controller extends Controller{

public function __construct()
    {
    parent::Controller();
    $this->get_site_status();
    }
    
protected function get_site_status()
    {
    if($this->config->item('site_online') == FALSE)
        {
        show a custom page here .    
        }
    }

Ok , now i thought that if i cand duplicate the show_error() function and change it a bit would feet my needs , so i tried to extend the Exceptions class as follows:
Code:
class MY_Exceptions extends CI_Exceptions{

public function __construct()
    {
    parent::CI_Exceptions();
    }

public function show_maintenance($template = 'maintenance', $status_code = 500)
    {
        set_status_header($status_code);

        if (ob_get_level() > $this->ob_level + 1)
        {
            ob_end_flush();    
        }
        ob_start();
        include(APPPATH.'errors/'.$template.EXT);
        $buffer = ob_get_contents();
        ob_end_clean();
        return $buffer;
    }
But when i try to load it , it says :
Fatal error: Class 'CI_Exceptions' not found in C:\wamp\www\ci\system\application\libraries\MY_Exceptions.php on line 8

So why this isn't working ?
I ended up by doing
Code:
class MY_Controller extends Controller{

public function __construct()
    {
    parent::Controller();
    $this->get_site_status();
    }
    
public function get_site_status()
    {
    if($this->config->item('site_online') == FALSE)
        {
        $error =& load_class('Exceptions');
        echo $error->show_error($this->config->item('site_name'), $this->config->item('site_offline_message'), 'maintenance', 200);
        exit;    
        }
    }

How correct is that ?
Any suggestions on doing this in the right way ?
Thank you .

#2
[eluser]überfuzz[/eluser]
My suggestion is that we should start looking at the error-message.
Code:
Fatal error: Class ‘CI_Exceptions’ not found in C:\wamp\www\ci\system\application\libraries\MY_Exceptions.php on line 8
First step: Look in your file-system, start here: C:\wamp\www\ci\system\application\libraries\, and see if theres a file called CI_Exceptions.php

#3
[eluser]wiredesignz[/eluser]
@Twisted1919, Using the load_class() method is perfectly acceptable if you need to load your extension of a core library.

#4
[eluser]Twisted1919[/eluser]
@uberfuzz - Actually the class filename is Exceptions.php , and yes it's there .

@wiredesignz - Thank you , i got it sorted out without extending the exceptions class .


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.