The PrettyPageHandler renders a user-friendly HTML error page. You can customize its appearance, behavior, and the data it displays.
Customizing Appearance
- Page Title: Use
setPageTitle($title) to change the title displayed in the browser tab and header. - Custom CSS: Use
addCustomCss($name) to load an additional CSS file from your resource paths. - Custom JS: Use
addCustomJs($name) to load an additional JavaScript file from your resource paths.
Customizing Data Display
By default, the handler displays superglobals like $_GET, $_POST, etc. You can add your own data tables to the error page:
- Static Data: Use
addDataTable($label, array $data) to add a table with a fixed associative array. - Dynamic Data: Use
addDataDataTableCallback($label, callable $callback) to add a table where the content is generated lazily when the error is rendered. The callback receives the Whoops\Inspector\InspectorInterface as an argument.
Security and Privacy
To prevent sensitive information from being displayed in the error page, you can hide specific keys from superglobal arrays using blacklist($superGlobalName, $key) or hideSuperglobalKey($superGlobalName, $key).
Example superglobal names: '_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER', '_ENV'.
$handler = new Whoops\Handler\PrettyPageHandler();
// Customize appearance
$handler->setPageTitle('My App Error');
$handler->addCustomCss('my-styles.css');
// Add custom data
$handler->addDataTable('App Version', ['version' => '1.2.3']);
$handler->addDataTableCallback('User Context', function ($inspector) {
return ['user_id' => 42, 'role' => 'admin'];
});
// Hide sensitive data
$handler->blacklist('_SERVER', 'PHP_AUTH_PW');