CodeIgniter Forums
Extending CI_Session_files_driver - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- 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.
Example:

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

    public function 
get_data($key)
    {
        
$keys explode('/'trim($key"/"));
        if (
count($keys) > 1) {
            return 
$this->_get_data_desde_ruta($keys);
        }
        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:
$this->session 
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!