Jump to content

Strange behaviour with $session


Tom.
 Share

Recommended Posts

Sorry, I know I'm full of questions today. However I've come across this. I want to be able to set a session that will store PageIDs for this user journey thing I'm doing. However there is only two templates I want to set the $session on, so if they visit a page that isn't part of the user journey it will reset all PageIDs. 

I'm using:

<?php if(!$page->is("template=question|document")) { $session->journey = ''; } ?>

However, this will reset on pages that belong to question or document. But the strange thing is, I tried:

<?php if(!$page->is("template=question|document")) { $session->journey = ''; echo "Hello"; } ?>

The header.php that this file is in, is using require. Is it possible that this:

$inArray = false;
foreach($journey as $item) {
    if($item == $page) {
        $prev = $journey->getPrev($item);
        $next = $journey->getNext($item);
        if($prev) echo "<a href='$prev->url' class='uk-button uk-button-small'><i class='icon-uniE171'></i> $prev->title</a>";
        if($next) echo "<a href='$next->url' class='uk-button uk-button-small uk-align-right'>$next->title <i class='icon-uniE16F'></i></a>";
$inArray = true;
    }
}
if(!$inArray) {
    $session->journey = '';
}

is firing before and returning false due to:

$journey = $pages->find("id=$session->journey");

Removing this line: 

<?php if(!$page->is("template=question|document")) { $session->journey = ''; } ?>

Stops the session from being cleared on the document or question page. However again echoing anything out from there doesn't display. 

I'm really confused with this one. Any help is deeply appreciated. 

Link to comment
Share on other sites

Thanks for making the video but I'm sorry, from what I see, I cannot explain the behaviour.

Yup, it's got me pretty dumbfounded too. Maybe I will swap to using PHP's standard $session. Maybe it has something to do with ProcessWire's 3.0 compiler?

EDIT:

When you are logged out, this problem doesn't exist. I'm guessing when you are logged in it redirects to an admin template to enable the front-end editing the displays the page. Resulting in that else firing? 

EDIT2:

Disabling and enabling the Front-End editing module fixed this issue. 

EDIT3:

Disabling and enabling the Front-End editing module only fixes it for a short amount of time.

EDIT4:

I've created a video to better illustrate the problem I'm facing: 

Link to comment
Share on other sites

Just an update, this is still happening on 3.0.4. It will work fine for a little while, I thought it was fixed in 3.0.4 but then it would just suddenly revert back to not working again. That seems strange to me. 

No code changes were made between it working and not working. As previous, uninstalling and reinstalling the Front-End Edit module get's it working fine again for about 15-30 minutes. (Both the Front-End editing and the session works fine).

Anyone have ideas? 

Link to comment
Share on other sites

Just an update for anyone who may hit this issue in future. Wrapping your $session in an the following if statement works.

$(!$config->ajax) {

}

It's because the front-end editing when activated reloads the page using ajax. More on it here: https://github.com/ryancramerdesign/ProcessWire/issues/1602#issuecomment-172309783 - Thanks Ryan for clearing it up.

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...