We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

SOLVED: $SESS->cache persistent between extension and plugin?

Development and Programming

Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Hey guys,

From my tests $SESS->cache doesn’t seem to be persistent between the sessions_start hook and when I try and use it in a plugin on the same page load.

Can one of the EE team or one of the independent developers confirm / explain this?

I thought the $SESS was persistent until the page was finished loading

Cheers

       
Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

I have successfully used $SESS->cache to pass data between an extension and a plugin. In my case, I used the comment_entries_tagdata hook.

Do you have a simplified use case showing the problem?

       
Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

After taking a look at the hook (which I should have done before posting my first message), I wonder if you’re forgetting to use a reference. Does your function look something like A or B?

A: function my_session_start_function(&$OBJ)
B: function my_session_start_function($OBJ)
       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Or referencing the global $SESS object and changing that instead of the passed object would likely be sufficient.

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Hey guys,

I have attached a simple example that demonstrates the issue.

Use {exp:lg_pi_test:render} to output the PI $SESS data.

From what I can tell it looks like the plugins create a new $SESS variable???? maybe.

It would be great if one of you guys could take a look at this for me 😊

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Ah, that hook is inside the Session class constructor so until it finishes running the constructor, PHP will not have assigned anything to the $SESS global variable yet. So accepting by reference will be needed (at least for PHP 4 compatibility - 5 will pass objects by reference by default if memory serves):

function sessions_start(&$obj)
{
    $obj->cache['lg'] = 'test';
}
       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham
Ah, that hook is inside the Session class constructor so until it finishes running the constructor, PHP will not have assigned anything to the $SESS global variable yet. So accepting by reference will be needed (at least for PHP 4 compatibility - 5 will pass objects by reference by default if memory serves):
function sessions_start(&$obj)
{
    $obj->cache['lg'] = 'test';
}

Thanks Derek…

much nicer than my

// check if the session exists if not start one
if(session_id() == "") session_start();
// create an empty array for the language files
$_SESSION['lg_ml']['languages'] = array();

Work around

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

eek! Indeed. ::holds up garlic and a wooden stake to $_SESSION::

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham
After taking a look at the hook (which I should have done before posting my first message), I wonder if you’re forgetting to use a reference. Does your function look something like A or B?
A: function my_session_start_function(&$OBJ)
B: function my_session_start_function($OBJ)

I guess you where right as well… 😊

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Thanks for bot of your help…

The documentation for the addon can be found here. The addon should be available soon.

Cheers again. If I was at SXSW I would buy you both a beer

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Check for last minute cheap flights across the pond, Leevi! If you make it, I’ll buy you the beer.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.