SOLVED: $SESS->cache persistent between extension and plugin?
Posted: 19 February 2008 05:53 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

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

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 February 2008 10:23 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  750
Joined  08-16-2003

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?

 Signature 

Pst… have you taken a look at Weever yet?

Profile
 
 
Posted: 19 February 2008 10:31 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  750
Joined  08-16-2003

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)

 Signature 

Pst… have you taken a look at Weever yet?

Profile
 
 
Posted: 19 February 2008 10:44 AM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15845
Joined  06-03-2002

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

 Signature 
Profile
MSG
 
 
Posted: 19 February 2008 03:24 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

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 smile

File Attachments
archive.zip  (File Size: 2KB - Downloads: 93)
 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 February 2008 03:36 PM   [ Ignore ]   [ # 5 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15845
Joined  06-03-2002

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';
}

 Signature 
Profile
MSG
 
 
Posted: 19 February 2008 03:42 PM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006
Derek Jones - 19 February 2008 03:36 PM

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

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 February 2008 03:44 PM   [ Ignore ]   [ # 7 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15845
Joined  06-03-2002

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

 Signature 
Profile
MSG
 
 
Posted: 19 February 2008 03:44 PM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006
Mr. Wilson - 19 February 2008 10:31 AM

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… smile

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 February 2008 06:08 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

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

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 February 2008 06:39 PM   [ Ignore ]   [ # 10 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15845
Joined  06-03-2002

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

 Signature 
Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65020 Total Logged-in Users: 42
Total Topics: 82108 Total Anonymous Users: 24
Total Replies: 441247 Total Guests: 206
Total Posts: 523355    
Members ( View Memberlist )