$process→pageNotFound()
Called when a page is not found, sends 404 header, and displays the configured 404 page instead.
Method is hookable, for instance if you wanted to log 404s. When hooking this method note that it must be hooked sometime before the ready state.
This protected method is for hooks to monitor and it is likely not intended to be called directly.
Internal usage
// basic internal usage
$string = $process->pageNotFound($page, string $url);
// internal usage with all arguments
$string = $process->pageNotFound($page, string $url, bool $triggerReady = false, string $reason = '', $exception = null);Arguments
| Name | Type(s) | Description |
|---|---|---|
$page | Page null | Page that was found if applicable (like if user didn't have permission or $page's template threw the 404). If not applicable then NULL will be given instead. |
$url | string | The URL that the request originated from (like $_SERVER['REQUEST_URI'] but already sanitized) |
$triggerReady (optional) | bool | Whether or not the ready() hook should be triggered Default:false |
$reason (optional) | string | Reason why 404 occurred, for debugging purposes (en text) |
$exception (optional) | WireException Wire404Exception | Exception that was thrown or that indicates details of error |
Return value
string
Exceptions
Method can throw exceptions on error:
WireException
Hooking $process→pageNotFound(…)
You can add your own hook events that are executed either before or after the $process method is executed. Examples of both are included below. A good place for hook code such as this is in your /site/ready.php file.
Hooking before
The 'before' hooks are called immediately before each $process method call is executed. This type of hook is especially useful for modifying arguments before they are sent to the method.
$this->addHookBefore('ProcessPageView::pageNotFound', function(HookEvent $event) {
// Get the object the event occurred on, if needed
$process = $event->object;
// Get values of arguments sent to hook (and optionally modify them)
$page = $event->arguments(0);
$url = $event->arguments(1);
$triggerReady = $event->arguments(2);
$reason = $event->arguments(3);
$exception = $event->arguments(4);
/* Your code here, perhaps modifying arguments */
// Populate back arguments (if you have modified them)
$event->arguments(0, $page);
$event->arguments(1, $url);
$event->arguments(2, $triggerReady);
$event->arguments(3, $reason);
$event->arguments(4, $exception);
});Hooking after
The 'after' hooks are called immediately after each $process method call is executed. This type of hook is especially useful for modifying the value that was returned by the method call.
$this->addHookAfter('ProcessPageView::pageNotFound', function(HookEvent $event) {
// Get the object the event occurred on, if needed
$process = $event->object;
// An 'after' hook can retrieve and/or modify the return value
$return = $event->return;
// Get values of arguments sent to hook (if needed)
$page = $event->arguments(0);
$url = $event->arguments(1);
$triggerReady = $event->arguments(2);
$reason = $event->arguments(3);
$exception = $event->arguments(4);
/* Your code here, perhaps modifying the return value */
// Populate back return value, if you have modified it
$event->return = $return;
});$process methods and properties
API reference based on ProcessWire core version 3.0.253