CodeIgniter Forums
Extending CI_Session_files_driver - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: Extending CI_Session_files_driver (/showthread.php?tid=1615)

Extending CI_Session_files_driver - CiUser - 03-25-2015

Hello, I'd need to extend CI_Session_files_driver class in order to add my own method.

PHP Code:
class MY_Session_files_driver extends CI_Session_files_driver
    public function 
__construct(array $params = array())

    public function 
$keys explode('/'trim($key"/"));
        if (
count($keys) > 1) {
        return isset(
$_SESSION[$key]) ? $_SESSION[$key] : NULL;

The extended driver is loaded correctly but the problem is that I can't access to the new method get_data().
PHP Code:
Fatal errorCall to undefined method CI_Session::get_data() 
I guess that the problem is that as get_data() is not part of the interface of CI_Session and
PHP Code:
is an instance of CI_Session, it not recognize as an existing method. May be?

Do you know any way to extend the driver adding new methods?

RE: Extending CI_Session_files_driver - Narf - 03-26-2015

You need to extend CI_Session, not CI_Session_files_driver.

RE: Extending CI_Session_files_driver - CiUser - 03-26-2015

But, CI_Session is abstract and if I extend from this I'd need to implement all its abstract method.
This is not my aim

RE: Extending CI_Session_files_driver - mwhitney - 03-26-2015

CI_Session_driver is abstract. CI_Session is not.

RE: Extending CI_Session_files_driver - CiUser - 03-26-2015

Cool, will try!

RE: Extending CI_Session_files_driver - CiUser - 03-28-2015

I could resolve the problem.
I created a class at /application/libraries/Session/MY_Session.php extendig from CI_Session and added my own methods on it and works fine.

Thanks all for your help!