From a4db3c8391319baeed1d775cfdbd9a9fb5ecd9fd Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Putra Date: Tue, 5 Sep 2017 13:37:16 +0700 Subject: [PATCH] Fixing PDO fetching --- App/Controllers/Posts.php | 8 +- App/Models/Post.php | 2 +- App/Views/Data/edit_pengumuman.html | 218 ++++++++++++++-------------- 3 files changed, 111 insertions(+), 117 deletions(-) diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index 5481b11..8580831 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -45,18 +45,18 @@ class Posts if (is_array($id)) { $id = implode('', $id); } - $posts = $this->post->showSingle($id); + $post = $this->post->showSingle($id); $categories = $this->post->showCategories(); - $users = $this->access->showSingle($id); + $user = $this->access->showSingle($id); $date = new \DateTime(); $timestamp = $date->format("Y/m/d H:i:s"); // echo "You can edit exists data with id $id here"; // Nanti di replace sama twig view ke App\Views\Data\edit_pengumuman.html View::render( 'Data/edit_pengumuman.html', [ - 'posts' => $posts, + 'post' => $post, 'categories' => $categories, - 'users' => $users, + 'user' => $user, 'timestamp' => $timestamp, 'token' => Token::generate() ] diff --git a/App/Models/Post.php b/App/Models/Post.php index 71341e7..a5197fa 100644 --- a/App/Models/Post.php +++ b/App/Models/Post.php @@ -63,7 +63,7 @@ class Post extends \Core\Model if ($query->execute([$id])) { if ($query->rowCount() === 1) { - $result = $query->fetchAll(\PDO::FETCH_ASSOC); + $result = $query->fetch(\PDO::FETCH_ASSOC); return $result; } } diff --git a/App/Views/Data/edit_pengumuman.html b/App/Views/Data/edit_pengumuman.html index 6abf107..3450b78 100644 --- a/App/Views/Data/edit_pengumuman.html +++ b/App/Views/Data/edit_pengumuman.html @@ -3,124 +3,118 @@ {% block title %}Edit Pengumuman{% endblock %} {% block body %} - {% for post in posts %} +
+

Pengumuman {{ post.id }}

+ + + + +
+ + + + +
+ + + + {{ post.created_at }} + + +
+ + + + {% if post.creator == user.id %} + {{ user.name }} + {% endif %} + + +
+ + + + {{ post.expired_at }} + + +
+ + + + {% if post.edited_at == "0000-00-00 00:00:00" %} + Tidak pernah + {% else %} + {{ post.edited_at }} + {% endif %} + + + +
+ + + + {% if post.editor == "0" %} + - + {% else %} + {% if post.editor == user.id %} + {{ user.name }} + {% endif %} + {% endif %} + + + +
+ + + + {% if post.status == 0 %} + Nonaktif + {% else %} + Aktif + {% endif %} + + + + + + + + + + + +
+ + +
+ + {% if post.status == 1 %}
-

Pengumuman {{ post.id }}

- - - - -
- - - - -
- - - - {{ post.created_at }} - - -
- - - - {% for user in users %} - {% if post.creator == user.id %} - {{ user.name }} - {% endif %} - {% endfor %} - - -
- - - - {{ post.expired_at }} - - -
- - - - {% if post.edited_at == "0000-00-00 00:00:00" %} - Tidak pernah - {% else %} - {{ post.edited_at }} - {% endif %} - - - -
- - - - {% if post.editor == "0" %} - - - {% else %} - {% for user in users %} - {% if post.editor == user.id %} - {{ user.name }} - {% endif %} - {% endfor %} - {% endif %} - - - -
- - - - {% if post.status == 0 %} - Nonaktif - {% else %} - Aktif - {% endif %} - - - - + - + -
- - +
- - {% if post.status == 1 %} -
- - - - - - - - - -
- {% endif %} - {% endfor %} + {% endif %} {% endblock %}