Detect previous page visited

Permalink
I need a method to get the Handle of the previous page that the viewer visited. I see that the dashboard's drop down menu's first line is tracking the last 5 recent pages that the viewer visited but this stuff is pretty well hidden and I can't find it's code for a sample. I have searched extensively for any helper that can give me this information without success. Does anyone have a suggestion other than rcID or [HTTP_REFERER]? These are both undependable. I briefly looked at the "next previous" block but it looks like it's based on site navigation and not on actual pages visited.

ThomasJ
 
hutman replied on at Permalink Reply
hutman
You could try something like this in the header of your site:
$c = Page::getCurrentPage();
if(intval($_SESSION['currentPage']) > 0){
    $_SESSION['previousPage'] = intval($_SESSION['currentPage']);
}
$_SESSION['currentPage'] = $c->getCollectionHandle();

then use those variables wherever you need them to do what you want.
ThomasJ replied on at Permalink Reply
ThomasJ
thanks so much for this. I've been so wrapped up in writing code that I forgot all about the header & footer. However, I don't think this will work for me either. Whatever I use has to be able to be installed by a pachage controller into any concrete5 website.
JohntheFish replied on at Permalink Reply
JohntheFish
You can do the same in a package controller. Use an on_start handler to set up an on_before_render handler and set the page tracker into the session within that.

You could save it into an array as a stack rather than a fixed value. There may be situations involving a redirect that would confuse a single value. If you do, trim the length to prevent it growing too big

An alternative strategy would be to make a database query on the PageStatistics table and get the last entry. That should work as long as statistics are not disabled. Same provision as above on redirects possibly confusing things slightly.
ThomasJ replied on at Permalink Reply
ThomasJ
Wow! Thank you for this reply. By the way you worded it, I am assuming that your response is based on my submission to the marketplace, "Message Bar'. This is the reason for this Forum search.

I am almost embarrassed to respond back to you with a sense that it may show an unfamiliarity with Concrete5, even though I have been working with it now for a couple of years. Concrete5 is a really deeply constructed work. No matter, how much I search, there are a lot subtleties on it's operation that are buried within it.

Here are thequestions I am left with:
1) How would one create an on_before_render handler from within the on_start method in the installer controller?
2) Where is this created method going to be placed if not in the same controller?
3) If this created method is to run from the installer controller, wouldn't it have to run every time a request for a page is passed to the website?

What I need is a Hook into the Dispatcher load. Is this possible? I have just visited a Forum Post created by someone else needing this same thing.
JohntheFish replied on at Permalink Reply
JohntheFish
Event setup and execution is not that big an overhead. But it is a bigger overhead than a core override.

However, a core override like you are thinking of would be marginal on approval, it may just creep in as black.

You can find example code for the events in the package controller of my Load jQuery.UI addon (look at the attribute version, not the block version)

Rather than events, using PageStatistics would probably be more efficient (but you never can tell until you run a benchmark).

Another way to do it would be with some javascript to set a cookie for every page after it has loaded. You could then read the cookie from php.

All of the above would fall down to some extent when full page caching is force enabled. (but then so does pretty much anything interactive).
ThomasJ replied on at Permalink Reply
ThomasJ
MY EYES ARE OPEN WIDE! Very, very nice. This is what I have been looking for for a very long time. I have used Events with great success in site_events.php. The way the documentation reads for Events gives the impression that Events::extend() has to be placed in the site_events.php file for it to engage the method defined in order to give it site wide functionality. You just opened my eyes to Events::extend() actually embeds a hook into the loading process and runs every time the prescribed event fires on every page load until it is removed. I say again, thanks. This is exactly what I need from c5.
ThomasJ replied on at Permalink Reply
ThomasJ
I have added this new approach to my package and Events::extend() is working quite well for me. Thanks.

I would like to know how to remove an event handler after it has been set in the on_start method. I noticed in your package that you have no code to remove your event handler in your uninstall method other than the call to parent::uninstall(). Does this automatically remove any hooks generated by the installer controller?

I have one more thing puzzling me. After installing my package, the block selection menu shows only half of a selection bar and no title. I haven't been able to find anything that may be causing this.

Thanks,
ThomasJ
enlil replied on at Permalink Reply
enlil
as far as the block selection oddity, see my comments in PRB about the block type name and description. Your controller is missing the "description" part, which is what is causing the add block dialogue to look funny :)
JohntheFish replied on at Permalink Reply
JohntheFish
There is no c5 equivalent to the jQuery off() and one() methods.

Event handlers in packages disappear when the package is uninstalled.
ThomasJ replied on at Permalink Reply
ThomasJ
Thank you much. I am not using Js or Jquery for this. It's good to know that c5 is doing the housekeeping for us.

I have uploaded the next version to look at, 0.9.6.

Thanks