Jump to content

$session variable disappeares when Ajax loaded ?


celfred
 Share

Recommended Posts

Hello,

I'm facing a weird issue here. I have a page loaded with this code inside (my comments in line ends) :

if ($session->allPlayers) { // Set in a head.inc file. I have also a $session->set('allTeams', $allTeams); in my head.inc
  $allPlayers = $session->allPlayers;
} else {
  $allPlayers = getAllPlayers($user, false);
  $session->set('allPlayers', $allPlayers);
}
bd($session->getAll()); // HERE, I get a number of 11 variables which is what I expect

In the same page, I have a link pointing to ajaxContent.php that loads stuff via Ajax.

I just write this in my ajaxContent.php to test :

bd($session->getAll()); // HERE, I get only 9 variables. All my newly set $session variables ($allTeams and $allPlayers) are not conveyed to ajaxContent.php ???

Would you have any idea why is that ??? Another thing : I have a $session->headMenu set in my head.inc, and this one works fine. I can retrieve it in my ajaxContent.php page.

I've tried cleaning all caches but it doesn't change anything ? 

At first, I expected it to be a 15-minute update to my site... It turns out to be a 2-hour issue and I'm still  stuck.

Thanks for your ideas ! 

Link to comment
Share on other sites

What does getAllPlayers() do? Does this contain a selector with permission access? Perhaps checking in a incognito screen to check if you get both scenarios the same variables.

Link to comment
Share on other sites

Thanks for your concern @arjen. I appreciate your help.

35 minutes ago, arjen said:

What does getAllPlayers() do? Does this contain a selector with permission access?

It doesn't do much except a $pages->find("template=player, team=$selectedTeam") according to the logged in user.

But your comment made me think of another test. I simplified by wroting :

 $session->set('allPlayers', 'test');

But I get nothing on my ajaxContent.php page... $session->getAll() lists previously set variables only.

So I kept trying things and went on delogging my user and trying to re-log and noticed it didn't work as expected any longer. So I switched to my dev branch and logging in functionality came back. So I started inspecting my code and here's what I noticed :

  • If I put this in my head.inc :

$session->set('allTeams', 'test');

Everything works as expected. No more issue anywhere.

  • If i put this instead :

$session->set('allTeams, $allTeams);

$allTeams being a pageArray that the actual logged-in user receives from a $pages request (actually the different classes for the logged-in teacher), my logging-in system doesn't work any longer and I get my initial issue. Actually, I interpret this as an impossibility to update in any way my $session...

 

So I'm slowly stepping forward, but I still don't understand anything about this behavior...

You also mentionned :

52 minutes ago, arjen said:

Perhaps checking in a incognito screen to check if you get both scenarios the same variables.

And I have no idea of what that means, sorry... If incognito screen is a 'guest' view, for the moment, I just want a specific role to have this functionality.

I stay tuned for explanations ? 

Link to comment
Share on other sites

Oh, I've just re-re-re-re-read the API documentation, and maybe I've seen something :

Does $session->set($key, $value) only work with strings for $value ? Maybe this is my issue trying to pass a PageArray ???

And then, how would you do that, then, passing a 'big' pageArray without having to do the DB request again ? I thought I could do it through $session ?

Link to comment
Share on other sites

You are safe to store a regular array in the session variable. See this old thread: 

I would worry to much about performance since only looking up ID's is very fast since you are not joining.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...