Welcome Guest, Not a member yet? Register   Sign In
extend core class CI_Session problem
#1

[eluser]mdr[/eluser]
Hi ppl
I'm do something wrong and I need help with my problem

I created the Session.php in application/libraries with the next code:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Session extends CI_Session {
    
     function MY_Session()
     {
         parent::CI_Session();        
         if (!$this->getSessionLang()) {
             $CI = &get;_instance();
             $CI->config->load('site',true);
             $this->set_userdata('lang',
                 $CI->config->item('deflang','site'));
         }
     }
    
     function setSession($data = array())
     {
         $this->set_userdata($data);
     }
    
     function getSessionLang()
    {
        return $this->userdata('lang');
    }
    
    function setSessionLang($varlang = "")
    {
        $CI = &get;_instance();
        $CI->load->library('util');
        if ($CI->util->isValidLang($varlang))
            $this->set_userdata('lang',$varlang);
    }
}
?>

And error is:
Fatal error: Class 'Session' not found in /usr/local/www/geowines/system/application/libraries/Session.php on line 2

line 2 is class MY_Session extends CI_Session....

any idea?
#2

[eluser]drewbee[/eluser]
When you are loading the library, you are doing this?

Code:
$this->load->library('session');

and not
Code:
$this->load->library('my_session');

Correct?
#3

[eluser]mdr[/eluser]
yes, but don't work and I solve rename file and class and load with the new name

Code:
$this->load->library('sitesession');

thanks
#4

[eluser]Pascal Kriete[/eluser]
The original problem would be solved by calling the file MY_Session.php instead of Session.php.
#5

[eluser]mdr[/eluser]
Yes, I was confused, but its works thanks for yours comments
#6

[eluser]Vang[/eluser]
the manual says that it should work in the first place:
Code:
$this->load->library('email');
An error in the manual i suppose ?
#7

[eluser]narkaT[/eluser]
[quote author="Vang" date="1226423362"]An error in the manual i suppose ?[/quote]

nope, inparo already posted why the code written in the manual didn't work.
the filename was missing the right prefix Wink
#8

[eluser]nikefido[/eluser]
I know this is old, but I just extended the core Session class (CI_Session to MY_Session) and when I loaded it, I used:
Code:
$this->load->library('session');

and it loaded the extended class, not the original one. I did NOT have to do:
Code:
$this->load->library('my_session');

CI ver 1.7.0
#9

[eluser]Unknown[/eluser]
For those starting with CI 2.0, this file will need to be in /application/core/ not /application/libraries/.
#10

[eluser]Unknown[/eluser]
Sorry for the major bump but.

Greg said that the MY_class should be in core not libraries. This is incorrect as far as my testing goes.

My case:

Version: 2.0

Extending CI_Session

Location: application/libraries/MY_Session.php
Definition:
Code:
class MY_Session extends CI_Session {

    public function __construct($params = array())
    {
        var_dump('yay!');
        die();
    }
}

Effectively replaces the constructor of CI_Session

Locating the same file under application/core fails to do so.


PS
I am also trying to replace CI_Model but haven't been successful at it. I will make a post about it if search on the forum results in no help.

-Edit-
only applicable to CI 2.0

CI_Session is located in system/libraries, hence MY_Session makes sense to be in application/libraries.

Made MY_Model work by locating the file in application/core. CI_Model resides in system/core so it makes sense to be in application/core.

The only other change you need to do is change your models (in application/models) to extend MY_Model not CI_Model. And if your model construct functions still contain the following:

Code:
parent::CI_Model();

change it to:

Code:
parent::__construct();


Location: application/core/MY_Model.php
Definition:

Code:
class MY_Model extends CI_Model
{
    function __construct()
    {
        var_dump('yay2!');
        die();
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB