From ca78aca8cb6507acf8bc5662a981f23232ec7062 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Wed, 14 Dec 2022 11:33:09 +0100 Subject: [PATCH] Permet de supprimer une news --- public/index.php | 1 + src/Silex/Router/Router.php | 5 +++++ views/edit.php | 1 + views/home.php | 16 +++++++++++++++- views/layout.php | 6 ++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/public/index.php b/public/index.php index 7a9431f..340fa1f 100644 --- a/public/index.php +++ b/public/index.php @@ -21,6 +21,7 @@ $router->match('/^register$/', [$security, 'register']); $router->match('/^logout$/', [$security, 'logout']); $router->match('/^admin\/publish$/', [$admin, 'publish']); $router->match('/^admin\/edit\/(?\d+)$/', [$admin, 'edit']); +$router->delete('/^admin\/delete\/(?\d+)$/', [$admin, 'delete']); $di = new \Silex\DI\DI($router); $router->run($di)->render($di, __DIR__ . '/../' . VIEW_PATH); diff --git a/src/Silex/Router/Router.php b/src/Silex/Router/Router.php index 8be3039..c6a0926 100644 --- a/src/Silex/Router/Router.php +++ b/src/Silex/Router/Router.php @@ -46,6 +46,11 @@ class Router return $this->addRoute(['GET', 'POST'], $path, $callable); } + public function delete(string $path, callable $callable): self + { + return $this->addRoute(['DELETE'], $path, $callable); + } + private function addRoute(array $methods, string $path, $callable): self { $route = new Route($path, $callable); diff --git a/views/edit.php b/views/edit.php index 0d7d9f9..689c351 100644 --- a/views/edit.php +++ b/views/edit.php @@ -1,3 +1,4 @@ +
diff --git a/views/home.php b/views/home.php index 91d90c1..f39a043 100644 --- a/views/home.php +++ b/views/home.php @@ -16,6 +16,9 @@

getPublicationDate()->format('Y-m-d') . " : " . $news->getTitle() ?> + getCurrentUser() !== null && $security->getCurrentUser()->isAdmin()): ?> + +

@@ -68,4 +71,15 @@ - \ No newline at end of file + + +getCurrentUser() !== null && $security->getCurrentUser()->isAdmin()): ?> + + \ No newline at end of file diff --git a/views/layout.php b/views/layout.php index f0d76b2..9601e8d 100644 --- a/views/layout.php +++ b/views/layout.php @@ -11,6 +11,12 @@