Jump to content

Can't hook 404 Page via ProcessPageView::pageNotFound


bernhard
 Share

Recommended Posts

Am I missing something obvious with my code? This does not work, neither addHookBefore not addHookAfter:

// site/ready.php and also in init() of an autoload module
bd('ready!');
$wire->addHookBefore('ProcessPageView::pageNotFound', function($event) {
  bd('test');
  die('test');
});

It logs "ready" but does not fire the hook. I tried it in 2 different installations. Dumping bd('test') inside of pageNotFound() in ProcessPageView.php works, so the method get's executed but the hook never gets called?! ? 

@Robin S you've once told me that you hook the 404 page for some REST stuff, but I could not find that post any more.

Thx for your help everybody ? 

Link to comment
Share on other sites

6 minutes ago, bernhard said:

Am I missing something obvious with my code? This does not work, neither addHookBefore not addHookAfter:


// site/ready.php and also in init() of an autoload module
bd('ready!');
$wire->addHookBefore('ProcessPageView::pageNotFound', function($event) {
  bd('test');
  die('test');
});

It logs "ready" but does not fire the hook. I tried it in 2 different installations. Dumping bd('test') inside of pageNotFound() in ProcessPageView.php works, so the method get's executed but the hook never gets called?! ? 

Just for a test copied this to /site/init.php, removed bd() calls (don't have Tracy installed), and it worked like a charm. 404 page gave me "test".

So... another module, another hook, Tracy (?), or something else interfering?

You mentioned site/ready.php and init() of an autoload module, but in my test I used site/init.php. That probably shouldn't matter in this case – though not 100% sure ?

  • Thanks 1
Link to comment
Share on other sites

Thank you teppo, that brought me on the right track! It works in init.php but not in ready.php; My module was autoload="template!=admin" and changing that to autoload=true made it work. I guess when using selectors it has to wait for the API to be ready and then it is too late for the pageNotFound hook...

Not sure if that would be worth an issue report on github?

Link to comment
Share on other sites

  • 1 year later...

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...