Fixing PDO fetching
This commit is contained in:
parent
f8f4398007
commit
a4db3c8391
@ -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()
|
||||
]
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -3,124 +3,118 @@
|
||||
{% block title %}Edit Pengumuman{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
{% for post in posts %}
|
||||
<form method="post">
|
||||
<h3>Pengumuman {{ post.id }}</h3>
|
||||
|
||||
<label for="category">Kategori: </label>
|
||||
<select name="category">
|
||||
{% for cat in categories %}
|
||||
<option value="{{ cat.id }}"
|
||||
{% if post.category == cat.id %}
|
||||
selected
|
||||
{% endif %}
|
||||
>
|
||||
{{ cat.category }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<br>
|
||||
|
||||
<label for="content">Konten: </label>
|
||||
<textarea name="content" rows="3" cols="30">{{ post.content }}</textarea>
|
||||
|
||||
<br>
|
||||
|
||||
<label>Dibuat pada: </label>
|
||||
<span>
|
||||
{{ post.created_at }}
|
||||
</span>
|
||||
|
||||
<br>
|
||||
|
||||
<label>Dibuat oleh: </label>
|
||||
<span>
|
||||
{% if post.creator == user.id %}
|
||||
{{ user.name }}
|
||||
{% endif %}
|
||||
</span>
|
||||
|
||||
<br>
|
||||
|
||||
<label for="expired_at">Berlaku sampai: </label>
|
||||
<span>
|
||||
{{ post.expired_at }}
|
||||
</span>
|
||||
|
||||
<br>
|
||||
|
||||
<label>Diubah pada: </label>
|
||||
<span>
|
||||
{% if post.edited_at == "0000-00-00 00:00:00" %}
|
||||
Tidak pernah
|
||||
{% else %}
|
||||
{{ post.edited_at }}
|
||||
{% endif %}
|
||||
</span>
|
||||
<input type="hidden" name="edited_at" value="{{ timestamp }}">
|
||||
|
||||
<br>
|
||||
|
||||
<label for="editor_name">Diubah oleh: </label>
|
||||
<span>
|
||||
{% if post.editor == "0" %}
|
||||
-
|
||||
{% else %}
|
||||
{% if post.editor == user.id %}
|
||||
{{ user.name }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</span>
|
||||
<input type="hidden" name="editor" value="3"><!-- User -->
|
||||
|
||||
<br>
|
||||
|
||||
<label>Status: </label>
|
||||
<span>
|
||||
{% if post.status == 0 %}
|
||||
Nonaktif
|
||||
{% else %}
|
||||
Aktif
|
||||
{% endif %}
|
||||
</span>
|
||||
|
||||
<!-- Current Timestamp -->
|
||||
<input type="hidden" name="_currts" value="{{ timestamp }}" disabled>
|
||||
|
||||
<!-- Method -->
|
||||
<input type="hidden" name="_method" value="put">
|
||||
|
||||
<!-- Token -->
|
||||
<input type="hidden" name="_token" value="{{ token }}">
|
||||
|
||||
<br>
|
||||
|
||||
<button type="submit"
|
||||
{% if post.status == 0 %}
|
||||
disabled
|
||||
{% endif %}
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{% if post.status == 1 %}
|
||||
<form method="post">
|
||||
<h3>Pengumuman {{ post.id }}</h3>
|
||||
|
||||
<label for="category">Kategori: </label>
|
||||
<select name="category">
|
||||
{% for cat in categories %}
|
||||
<option value="{{ cat.id }}"
|
||||
{% if post.category == cat.id %}
|
||||
selected
|
||||
{% endif %}
|
||||
>
|
||||
{{ cat.category }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<br>
|
||||
|
||||
<label for="content">Konten: </label>
|
||||
<textarea name="content" rows="3" cols="30">{{ post.content }}</textarea>
|
||||
|
||||
<br>
|
||||
|
||||
<label>Dibuat pada: </label>
|
||||
<span>
|
||||
{{ post.created_at }}
|
||||
</span>
|
||||
|
||||
<br>
|
||||
|
||||
<label>Dibuat oleh: </label>
|
||||
<span>
|
||||
{% for user in users %}
|
||||
{% if post.creator == user.id %}
|
||||
{{ user.name }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</span>
|
||||
|
||||
<br>
|
||||
|
||||
<label for="expired_at">Berlaku sampai: </label>
|
||||
<span>
|
||||
{{ post.expired_at }}
|
||||
</span>
|
||||
|
||||
<br>
|
||||
|
||||
<label>Diubah pada: </label>
|
||||
<span>
|
||||
{% if post.edited_at == "0000-00-00 00:00:00" %}
|
||||
Tidak pernah
|
||||
{% else %}
|
||||
{{ post.edited_at }}
|
||||
{% endif %}
|
||||
</span>
|
||||
<input type="hidden" name="edited_at" value="{{ timestamp }}">
|
||||
|
||||
<br>
|
||||
|
||||
<label for="editor_name">Diubah oleh: </label>
|
||||
<span>
|
||||
{% if post.editor == "0" %}
|
||||
-
|
||||
{% else %}
|
||||
{% for user in users %}
|
||||
{% if post.editor == user.id %}
|
||||
{{ user.name }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</span>
|
||||
<input type="hidden" name="editor" value="3"><!-- User -->
|
||||
|
||||
<br>
|
||||
|
||||
<label>Status: </label>
|
||||
<span>
|
||||
{% if post.status == 0 %}
|
||||
Nonaktif
|
||||
{% else %}
|
||||
Aktif
|
||||
{% endif %}
|
||||
</span>
|
||||
|
||||
<!-- Current Timestamp -->
|
||||
<input type="hidden" name="_currts" value="{{ timestamp }}" disabled>
|
||||
<input type="hidden" name="id" value="{{ post.id }}">
|
||||
|
||||
<!-- Method -->
|
||||
<input type="hidden" name="_method" value="put">
|
||||
<input type="hidden" name="_method" value="delete">
|
||||
|
||||
<!-- Token -->
|
||||
<input type="hidden" name="_token" value="{{ token }}">
|
||||
|
||||
<br>
|
||||
|
||||
<button type="submit"
|
||||
{% if post.status == 0 %}
|
||||
disabled
|
||||
{% endif %}
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
<button type="submit">Nonaktif</button>
|
||||
</form>
|
||||
|
||||
{% if post.status == 1 %}
|
||||
<form method="post">
|
||||
<input type="hidden" name="id" value="{{ post.id }}">
|
||||
|
||||
<!-- Method -->
|
||||
<input type="hidden" name="_method" value="delete">
|
||||
|
||||
<!-- Token -->
|
||||
<input type="hidden" name="_token" value="{{ token }}">
|
||||
|
||||
<button type="submit">Nonaktif</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user