Skip to content

Commit 5afb591

Browse files
committed
update post -> fix problem update
1 parent ba91e6d commit 5afb591

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Controller/PostController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,16 @@ public function create()
154154
public function update()
155155
{
156156
$post = $this->session['post'];
157+
157158
$idPost = filter_input(INPUT_GET, 'id');
158159

159160
$titlePost = htmlspecialchars($post['content']['titre']);
160161
$description = htmlspecialchars($post['content']['description']);
161162
$contentPost = htmlspecialchars($post['content']['editor']);
162163
$datePost = new DateTime('now', new DateTimeZone('Europe/Paris'));
163164
$datePost = $datePost->format('Y-m-d H:i:s');
164-
$mainImagePath = 'assets/img/posts_images/' . self::getId() . '/' . $post['mainImg']['image']['name'];
165+
166+
$mainImagePath = $post['mainImg']['image']['name'] !== "" ? 'assets/img/posts_images/' . self::getId() . '/' . $post['mainImg']['image']['name'] : $post['content']['main_actual_img'];
165167

166168
ModelFactory::getModel('Post')->updateData($titlePost, ['title' => $titlePost, 'date' => $datePost, 'description' => $description, 'content' => $contentPost, 'main_img_path' => $mainImagePath], ['id' => $idPost]);
167169

src/View/admin/posts/update.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<input type="text" name="titre" id="titre" placeholder="Rentrez ici le titre de votre article" value="{{ posts.title }}" required>
1717
<label for="image">
1818
Choisissez l'image principale de l'article
19-
<input type="file" name="image" id="image" accept="image/x-png,image/gif,image/jpeg" required>
19+
<input type="file" name="image" id="image" accept="image/x-png,image/gif,image/jpeg">
20+
<input type="hidden" name="main_actual_img" value="{{ posts.main_img_path }}">
2021
</label>
2122
<h3>Rentrez une courte description de l'article</h3>
2223
<textarea name="description" id="description">{{ posts.description|raw }}</textarea>

0 commit comments

Comments
 (0)