Now can edit a category

This commit is contained in:
Gregorio Chiko Putra 2017-09-22 12:50:25 +07:00
parent 8b78715cd4
commit 0b1c3f3370
3 changed files with 30 additions and 33 deletions

View File

@ -163,9 +163,7 @@ class Posts
{ {
if (Session::exists('userid')) { if (Session::exists('userid')) {
if ($id) { if ($id) {
if (is_array($id)) {
$id = implode('', $id); $id = implode('', $id);
}
$get_categories = $this->model->showAll([ $get_categories = $this->model->showAll([
['status', '=', 1] ['status', '=', 1]
@ -220,7 +218,7 @@ class Posts
} }
} }
public function category() public function category($id = null)
{ {
if (Session::exists('userid')) { if (Session::exists('userid')) {
if (Session::get('privilege') != 1) { if (Session::get('privilege') != 1) {
@ -229,7 +227,19 @@ class Posts
die(); die();
} }
$categories = []; $categories = [];
$values = [];
$method = '';
if ($id != null) {
$id = implode('', $id);
$get_categories = $this->model->showAll([
['id', '=', $id]
], 'kategori');
$method = 'put';
$values = $get_categories;
} else {
$get_categories = $this->model->showAll([], 'kategori'); $get_categories = $this->model->showAll([], 'kategori');
$method = 'post';
}
if ($get_categories) { if ($get_categories) {
if (!array_key_exists(0, $get_categories)) { if (!array_key_exists(0, $get_categories)) {
@ -241,7 +251,9 @@ class Posts
View::render('Data/kategori.html', [ View::render('Data/kategori.html', [
'categories' => $categories, 'categories' => $categories,
'token' => Token::generate() 'token' => Token::generate(),
'method' => $method,
'value' => $values
]); ]);
} else { } else {
throw new \Exception("Page not found", 404); throw new \Exception("Page not found", 404);
@ -293,7 +305,7 @@ class Posts
$this->model->update($args, $args['id'], $table); $this->model->update($args, $args['id'], $table);
Session::flash('info', 'Data berhasil diaktifkan'); Session::flash('info', 'Update berhasil');
Redirect::to('/posts/category'); Redirect::to('/posts/category');
die(); die();
} }

View File

@ -1,20 +0,0 @@
{% extends "base.html" %}
{% block title %}Ubah Kategori{% endblock %}
{% block body %}
<main class="documentation">
<section>
<form method="post">
<div class="flex four-600 two">
<h1>Kategori
</h1>
<h1>
<input type="text" name="category" value="{{ category.category }}">
</h1>
</form>
</section>
</main>
{% endblock %}

View File

@ -5,7 +5,7 @@
{% block body %} {% block body %}
<main class="documentation"> <main class="documentation">
<section> <section>
<h1>Kategori</h1> <h1><a href="/posts/category">Kategori</a></h1>
<div class="flex two-600 full grow"> <div class="flex two-600 full grow">
@ -17,29 +17,34 @@
<label for="category">Nama</label> <label for="category">Nama</label>
</div> </div>
<div class="two-third-600 full"> <div class="two-third-600 full">
<input type="text" name="category"> <input type="text" name="category" value="{{ value.category }}">
</div> </div>
<div class="third-600 full"> <div class="third-600 full">
<label for="background">Background</label> <label for="background">Background</label>
</div> </div>
<div class="two-third-600 full"> <div class="two-third-600 full">
<input type="color" name="background"> <input type="color" name="background" value="{{ value.background }}">
</div> </div>
<div class="third-600 full"> <div class="third-600 full">
<label for="foreground">Teks</label> <label for="foreground">Teks</label>
</div> </div>
<div class="two-third-600 full"> <div class="two-third-600 full">
<input type="color" name="foreground"> <input type="color" name="foreground" value="{{ value.foreground }}">
</div> </div>
<input type="hidden" name="_method" value="post"> <input type="hidden" name="_method" value="{{ method }}">
<input type="hidden" name="_addon" value="kategori"> <input type="hidden" name="_addon" value="kategori">
<input type="hidden" name="_token" value="{{ token }}"> <input type="hidden" name="_token" value="{{ token }}">
<button type="submit" class="pseudo full"> <button type="submit" class="pseudo full">
{% if method == 'post' %}
<i class="fa fa-plus fa-fw" aria-hidden="true"></i> <i class="fa fa-plus fa-fw" aria-hidden="true"></i>
<span style="font-size:smaller;">Tambah</span> <span style="font-size:smaller;">Tambah</span>
{% else %}
<i class="fa fa-edit fa-fw" aria-hidden="true"></i>
<span style="font-size:smaller;">Ubah</span>
{% endif %}
</button> </button>
</div> </div>
</form> </form>
@ -58,7 +63,7 @@
<div class="flex two-600 full grow" style="margin:0;"> <div class="flex two-600 full grow" style="margin:0;">
<div> <div>
<a href="#" class="pseudo button full"> <a href="/posts/category/{{ cat.id }}" class="pseudo button full">
<i class="fa fa-edit fa-fw"></i> <i class="fa fa-edit fa-fw"></i>
<span style="font-size:smaller;">Ubah</span> <span style="font-size:smaller;">Ubah</span>
</a> </a>