Welcome Guest, Not a member yet? Register   Sign In
How to load singleton library
#1

[eluser]Hallas[/eluser]
Hello,

I have created library for logging, it is singleton class but in CI2 when I try to load it - it throws error :

Fatal error: Call to private Logger::__construct() from context 'CI_Loader'

even if I pass null as instance name.

$this->load->library('Logger','',null);

Can someone help about this ?

Code:
class Logger {
    private static $_instance;
    private $_fp;
    
    private function __construct()
    {
       $this->_fp = fopen('log.txt', 'a');
    }

    public function __destruct()
    {
        fclose($this->_fp);
    }

    public function log($text)
    {
        // Log stuff...
    }


    public static function getInstance()
    {
        if (self::$_instance === null) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
}


Messages In This Thread
How to load singleton library - by El Forum - 03-17-2012, 02:17 AM
How to load singleton library - by El Forum - 03-17-2012, 05:20 AM
How to load singleton library - by El Forum - 03-19-2012, 06:18 AM
How to load singleton library - by El Forum - 03-19-2012, 05:36 PM
How to load singleton library - by El Forum - 03-19-2012, 06:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB