Strange issue when detecting 404 Events
Permalink
What I'm trying to achieve: A dashboard page which lists all 404 events on the website
I previously had this working on 5.5.2.1, but when updating it to 5.6.3 RC2 I've come across a few issues.
In short, how I achieve it is by hooking into the on_start event as so:
CheckPage::checkPageStatus basically does:
For testing, I have modified it so that it outputs $page so I can see the path it's detected as erroneous.
Before I explain the problem, the structure of my site is as such:
/beavers/ exists
/beavers/programme/ exists
If I navigate to /beaverz/, a 404 entry is made correctly.
If I navigate to /beavers/test, a 404 entry is NOT made. When reading the values of $page, it shows the detected page as /beavers.
Even though it still throws the 404 page, it's detecting the page as loading as /beavers/. The status code is 404.
It's as if we try to navigate to an incorrect URL, if one of the previous levels is valid, that will be set for getCurrentPage().
Am I doing something wrong, or have I stumbled across some weird form of a bug? In addition, any more efficient event to use rather than the method? I could modify the 404 page to insert the entry, but I'd rather the package be self-contained.
Thanks in advance folks.
I previously had this working on 5.5.2.1, but when updating it to 5.6.3 RC2 I've come across a few issues.
In short, how I achieve it is by hooking into the on_start event as so:
Events::extend('on_start', 'CheckPage', 'checkPageStatus', DIRNAME_PACKAGES . '/' . $this->pkgHandle . '/' . DIRNAME_MODELS . '/check_page.php');
CheckPage::checkPageStatus basically does:
$page = getCurrentPage(); if($page->isError()) { // insert db entry }
For testing, I have modified it so that it outputs $page so I can see the path it's detected as erroneous.
Before I explain the problem, the structure of my site is as such:
/beavers/ exists
/beavers/programme/ exists
If I navigate to /beaverz/, a 404 entry is made correctly.
If I navigate to /beavers/test, a 404 entry is NOT made. When reading the values of $page, it shows the detected page as /beavers.
Even though it still throws the 404 page, it's detecting the page as loading as /beavers/. The status code is 404.
It's as if we try to navigate to an incorrect URL, if one of the previous levels is valid, that will be set for getCurrentPage().
Am I doing something wrong, or have I stumbled across some weird form of a bug? In addition, any more efficient event to use rather than the method? I could modify the 404 page to insert the entry, but I'd rather the package be self-contained.
Thanks in advance folks.
If you need the current page, the usual method is to use on_start to set up an on_before_render handler, where the page has been determined.