CodeIgniter Forums
Custom config in extended class (library) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Custom config in extended class (library) (/showthread.php?tid=57244)



Custom config in extended class (library) - El Forum - 02-28-2013

[eluser]JackU[/eluser]
I´m extended the Log class to email me and some other guys when an error occurs. But i can´t get my config to load. It´s located in the config directory and a subdir. Also i´m changing the threshold levels (in the construct). Why can´t i get my config?

('application/config/extra/appconf.php)

Code:
class MY_Log extends CI_Log {
function MY_Log()
    {
        parent::__construct();
        $this->_levels = array('ERROR' => '1', 'INFO' => '2',  'DEBUG' => '3', 'ALL' => '4');
    }

function write_log($level = 'error', $msg, $php_error = FALSE)
    {
        $result = parent::write_log($level, $msg, $php_error);
        
        //Get my config with emails.
        $this->ci =& get_instance();
        $this->ci->load->config('extra/appconf');
        echo $this->ci->config->item('sendto_emails');
    }
}



Custom config in extended class (library) - El Forum - 02-28-2013

[eluser]InsiteFX[/eluser]
Because it cannot be in a sub-directory.



Custom config in extended class (library) - El Forum - 02-28-2013

[eluser]JackU[/eluser]
That doesn´t seem to mather. It can´t be loaded if it is in main config dir or a sub dir.


Custom config in extended class (library) - El Forum - 02-28-2013

[eluser]InsiteFX[/eluser]
You should be loading it in the Constructor.



Custom config in extended class (library) - El Forum - 02-28-2013

[eluser]Aken[/eluser]
Also, the Log library is used well before get_instance() exists, so you won't be able to just call the CI object in there, or it'll throw errors.


Custom config in extended class (library) - El Forum - 03-01-2013

[eluser]JackU[/eluser]
Ok. So if the Log class is loaded to soon.

How do i load other stuff in the library or from the config? Or do i have to return to good old fashioned PHP coding style (not using any of the cool framework stuff) in order to make it work? Is this something that usually happens or is this just because of the Log class?