Error Pages
SigmaPHP provides built-in support for rendering error pages such as 404 and 500. By default, the framework looks
for error templates inside the Views/errors directory. A default 404.template.html file is
included, and you can create additional templates such as 403.template.html,
500.template.html, or any other HTTP error page your application may require.
These templates behave like regular views and can contain any template directives, variables, or layout structures used throughout the application.
For example, the following is the default 404 error template shipped with SigmaPHP.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 - Page Not Found</title>
<style>
body {
background-color: white;
font-family: sans-serif;
color: #ffa500;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
.container {
text-align: center;
}
.main-text {
font-size: 10em;
font-weight: bold;
margin-bottom: -0.1em;
line-height: 1;
}
.secondary-text {
font-size: 2em;
}
</style>
</head>
<body>
<div class="container">
<div class="main-text">404</div>
<div class="secondary-text">Page Not Found</div>
</div>
</body>
</html>
Returning an Error Page
Returning an error page from a controller action is straightforward. Simply render the appropriate error template and provide the corresponding HTTP status code.
if (empty($page)) {
return $this->error(404);
}
In this example, the framework renders the errors.404 template and returns it with the HTTP status code
404, allowing the browser and search engines to properly recognize the response as a "Page Not Found"
error.