Permet de supprimer une news
This commit is contained in:
@@ -21,6 +21,7 @@ $router->match('/^register$/', [$security, 'register']);
|
|||||||
$router->match('/^logout$/', [$security, 'logout']);
|
$router->match('/^logout$/', [$security, 'logout']);
|
||||||
$router->match('/^admin\/publish$/', [$admin, 'publish']);
|
$router->match('/^admin\/publish$/', [$admin, 'publish']);
|
||||||
$router->match('/^admin\/edit\/(?<id>\d+)$/', [$admin, 'edit']);
|
$router->match('/^admin\/edit\/(?<id>\d+)$/', [$admin, 'edit']);
|
||||||
|
$router->delete('/^admin\/delete\/(?<id>\d+)$/', [$admin, 'delete']);
|
||||||
|
|
||||||
$di = new \Silex\DI\DI($router);
|
$di = new \Silex\DI\DI($router);
|
||||||
$router->run($di)->render($di, __DIR__ . '/../' . VIEW_PATH);
|
$router->run($di)->render($di, __DIR__ . '/../' . VIEW_PATH);
|
||||||
|
@@ -46,6 +46,11 @@ class Router
|
|||||||
return $this->addRoute(['GET', 'POST'], $path, $callable);
|
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
|
private function addRoute(array $methods, string $path, $callable): self
|
||||||
{
|
{
|
||||||
$route = new Route($path, $callable);
|
$route = new Route($path, $callable);
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
<?php require 'errors.php' ?>
|
||||||
<form action="<?= $_SERVER['REQUEST_URI'] ?>" method="post">
|
<form action="<?= $_SERVER['REQUEST_URI'] ?>" method="post">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label" for="title">Title</label>
|
<label class="label" for="title">Title</label>
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
<header class="card-header">
|
<header class="card-header">
|
||||||
<p class="card-header-title">
|
<p class="card-header-title">
|
||||||
<?= $news->getPublicationDate()->format('Y-m-d') . " : " . $news->getTitle() ?>
|
<?= $news->getPublicationDate()->format('Y-m-d') . " : " . $news->getTitle() ?>
|
||||||
|
<?php if ($security->getCurrentUser() !== null && $security->getCurrentUser()->isAdmin()): ?>
|
||||||
|
<button class="button is-danger ml-4" onclick="deleteReq(<?= $news->getId() ?>); return false;">Delete</button>
|
||||||
|
<?php endif; ?>
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
@@ -68,4 +71,15 @@
|
|||||||
</li>
|
</li>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
<?php if ($security->getCurrentUser() !== null && $security->getCurrentUser()->isAdmin()): ?>
|
||||||
|
<script>
|
||||||
|
function deleteReq(i) {
|
||||||
|
fetch(`<?= $router->url('admin/delete/') ?>${i}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
}).then(() => location.reload());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
@@ -11,6 +11,12 @@
|
|||||||
<div id="navbarBasicExample" class="navbar-menu">
|
<div id="navbarBasicExample" class="navbar-menu">
|
||||||
<div class="navbar-start">
|
<div class="navbar-start">
|
||||||
<a class="navbar-item" href="<?= $router->url('') ?>">Home</a>
|
<a class="navbar-item" href="<?= $router->url('') ?>">Home</a>
|
||||||
|
|
||||||
|
<?php if ($security->getCurrentUser() !== null && $security->getCurrentUser()->isAdmin()): ?>
|
||||||
|
<a class="navbar-item" href="<?= $router->url('admin/publish') ?>">
|
||||||
|
Publish
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
|
Reference in New Issue
Block a user