Function edit works successfuly

This commit is contained in:
Gregorio Chiko Putra 2017-09-05 10:24:44 +07:00
parent c64064321e
commit 61060dd393
3 changed files with 45 additions and 12 deletions

View File

@ -42,12 +42,15 @@ class Posts
$id = implode('', $id);
$posts = $this->model->showSingle($id);
$categories = $this->model->showCategories();
$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,
'categories' => $categories,
'timestamp' => $timestamp,
'token' => Token::generate()
]
);
@ -65,4 +68,15 @@ class Posts
return $this->index();
}
}
public function put($args = [])
{
$table = 'pengumuman';
$id = $args['id'];
unset($args['id']);
if ($this->model->update($table, $args, $id)) {
Session::flash('info', 'Data successfuly updated');
return $this->index();
}
}
}

View File

@ -16,28 +16,47 @@
<br>
<label for="konten">Konten: </label>
<textarea name="konten" rows="3" cols="30">{{ post.content }}</textarea>
<label for="content">Konten: </label>
<textarea name="content" rows="3" cols="30">{{ post.content }}</textarea>
<br>
<label for="created_at">Dibuat pada: </label>
<input type="text" name="created_at" value="{{ post.created_at }}" readonly>
<label>Dibuat pada: </label>
<span>{{ post.created_at }}</span>
<br>
<label for="creator">Dibuat oleh: </label>
<input type="text" name="creator" value="{{ post.creator }}" readonly>
<label>Dibuat oleh: </label>
<span>{{ post.creator }}</span>
<br>
<label for="edited_at">Diubah pada: </label>
<input type="text" name="edited_at" value="{{ post.edited_at }}" readonly>
<label for="expired_at">Berlaku sampai: </label>
<span>{{ post.expired_at }}</span>
<br>
<label for="editor">Diubah oleh: </label>
<input type="text" name="editor" value="{{ post.editor }}" readonly>
<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 %}
{{ post.editor }}
{% endif %}
</span>
<input type="hidden" name="editor" value="3"><!-- User -->
<!-- Current Timestamp -->
<input type="hidden" name="_currts" value="{{ timestamp }}" disabled>
@ -51,6 +70,6 @@
<br>
<button type="submit" name="edit">Edit</button>
<button type="submit">Edit</button>
</form>
{% endblock %}

View File

@ -82,7 +82,7 @@ class Router
unset($var['_method']);
}
if (array_key_exists('id', $this->params)) {
$var[] = $this->params['id'];
$var['id'] = $this->params['id'];
}
if (isset($var)) {
return $object->$action($var);