[eluser]tanero[/eluser]
[quote author="Federico Biccheddu" date="1351098462"]Why doesn't work?
Code:
class MY_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file'));
}
}
On this class:
Code:
class Acl {
private $ci;
function __construct()
{
$this->ci =& get_instance();
if (!$foo = $this->ci->cache->get('foo'))
{
echo 'Saving to the cache!<br />';
$foo = 'foobarbaz!';
// Save into the cache for 5 minutes
$this->ci->cache->save('foo', $foo, 300);
}
echo $foo;
}
}
(Acl is loaded by autoload.php)
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$cache
Filename: libraries/Acl.php
Line Number: 13
Fatal error: Call to a member function get() on a non-object in application\libraries\Acl.php on line 13
[/quote]
You can not use MY_Controller class __construct function in your library, you just need to load cache driver in your Acl library.