route
Sets the response body.
Table of Contents
Description
This hook sets the response body based on the current URL information. The way your site responds to the current URL information is up to you. You can return any value from it. This application will consider it as information that can be used by the layout system to do something. The end result is usually converted to a string by the layout system in use.
The $content
variable starts with a null
value and will hold the value passed from the previous hook’s return value.
Example
Hook::set('route', function ($content, $path, $query, $hash) {
if ($path === '/about') {
return content('.\path\to\about.html');
}
return content('.\path\to\error.html');
}, 0);
Hook::set('route', function ($content, $path, $query, $hash) {
// The `$content` variable should now contain the contents of the `.\path\to\about.html` file if the value of
// `$path` variable is `'/about'`. Otherwise, it should contain the contents of the `.\path\to\error.html` file.
}, 1);
// This part should be the responsibility of the layout system.
$content = Hook::fire('route', [null, $url->path, $url->query, $url->hash]);
if (!is_string($content)) {
status(200);
type('application/json');
echo To::JSON($content, true);
} else {
status(200);
type('text/html');
echo $content;
}
body
Modifies the body part of the current HTML response.
content
Modifies the current HTML response.
enter
Modifies the current HTTP response headers.
exit
Fires after script execution ends.
get
Fires when the application is ready.
head
Modifies the head part of the current HTML response.
let
Fires when the application finishes rendering.
route
Sets the response body.
set
Fires when the application is ready.