Welcome Guest, Not a member yet? Register   Sign In
Extending CI_Session_files_driver
#1

(This post was last modified: 03-25-2015, 02:23 PM by CiUser.)

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?
Reply
#2

You need to extend CI_Session, not CI_Session_files_driver.
Reply
#3

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
Reply
#4

CI_Session_driver is abstract. CI_Session is not.
Reply
#5

Cool, will try!
Reply
#6

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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB