Welcome Guest, Not a member yet? Register   Sign In
Session in Language Files
#1

[eluser]joao.sobrinho[/eluser]
Hi.

I'm trying to use session data in some language files.

So far, I managed to use it like this:

the start of a language file:
Code:
$CI_session = &load;_class('Session');
$CI_session->keep_all_flashdata();
if(!isset($CI_session->userdata['var'])){
    $CI_session->userdata['var1_label'] = 'bla bla';
    $CI_session->userdata['var2_label'] = 'bla bla';
}

I use that if, to be sure that the data really exists for the rest of the file.


I changed the Session Class by adding this function to keep the flashdata
Code:
function keep_all_flashdata()
    {
        
        $userdata = $this->all_userdata();
        foreach ($userdata as $name => $value)
        {
            $parts = explode(':old:', $name);
            if (is_array($parts) && count($parts) === 2)
            {
                $new_flashdata_key = $this->flashdata_key.':new:'.$parts[1];
                $this->set_userdata($new_flashdata_key, $value);
            }
        }
    }

The problem with this, is that the session is loosing the data when it gets updated. It only happens when I set to use the database to sotre the session data, as I need to.

Any solution to use session data inside the language files ?
#2

[eluser]joao.sobrinho[/eluser]
Hi.

For now, I developed a plugin that goes to the database and gets the data I need in the language file.

That access do the bd, must be done using native php function because I get errors if I try to use the CI function because it's not completly loaded at the time I need to use them.

Until a beter solution apears, I'll roll with this one.

PS: If someone needs the file, I can drop it here later. It gets the connection data from the file in config folder. It has a problem if you change from mysql to any other db engine... But for me, this one will work until something better apears...




Theme © iAndrew 2016 - Forum software by © MyBB