changed php error view to twig error view + added css

pull/10/head
Vivien DUFOUR 1 year ago
parent eecf0689a6
commit ae375b8738

@ -35,6 +35,7 @@ $router = new AltoRouter();
$router->setBasePath($basePath);
$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig);
$errorController = new \App\Controller\ErrorController(new FormResultGateway($con), $twig);
$router->map("GET", "/", fn() => $sampleFormController->displayForm());
$router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST));
$router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig());
@ -43,9 +44,9 @@ $router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTw
$match = $router->match();
if ($match == null) {
// TODO redirect to a 404 not found page instead (issue #1)
$error = "404";
$errorController->displayError($error);
http_response_code(404);
echo "Page non trouvée";
exit(1);
}

@ -0,0 +1,34 @@
<?php
namespace App\Controller;
require_once __DIR__ . "/../react-display.php";
use App\Gateway\FormResultGateway;
use \Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
class ErrorController
{
private FormResultGateway $gateway;
private Environment $twig;
/**
* @param FormResultGateway $gateway
*/
public function __construct(FormResultGateway $gateway, Environment $twig)
{
$this->gateway = $gateway;
$this->twig = $twig;
}
public function displayError($error) {
$error = array("error" => $error);
try {
echo $this->twig->render('error.html.twig', $error);
} catch (LoaderError | RuntimeError | SyntaxError $e) {
echo "Twig error: $e";
}
}
}

@ -1,23 +0,0 @@
<html lang="fr">
<head>
<title>Error</title>
</head>
<body>
<h1>IQBall</h1>
<?php
if (isset($error)) {
if($error == "error404"){
echo "<h1>Erreur 404</h1>";
echo "<h3>Cette page n'existe pas</h3>";
}
}
?>
<button onclick="location.href='/'" type="button">Retour à la page d'accueil</button>
</body>
</html>

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Error</title>
{% block stylesheets %}
<style>
h1 { color: #da6110; text-align: center;}
h2 { text-align: center;}
.button { display: block; margin: 0 auto; cursor : pointer; background-color: white; color : black; text-align: center; font-size: 20px; border-radius: 12px; border : 2px solid #da6110}
.button:hover {background-color: #da6110}
</style>
{% endblock %}
</head>
<body>
<h1>IQBall</h1>
{% if error == "404" %}
<h2>Erreur 404 : cette page n'existe pas</h2>
{% endif %}
<button class="button" onclick="location.href='/'" type="button">Retour à la page d'accueil</button>
</body>
</html>
Loading…
Cancel
Save