Now can edit a category
This commit is contained in:
parent
8b78715cd4
commit
0b1c3f3370
@ -163,9 +163,7 @@ class Posts
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
if ($id) {
|
||||
if (is_array($id)) {
|
||||
$id = implode('', $id);
|
||||
}
|
||||
$id = implode('', $id);
|
||||
|
||||
$get_categories = $this->model->showAll([
|
||||
['status', '=', 1]
|
||||
@ -220,7 +218,7 @@ class Posts
|
||||
}
|
||||
}
|
||||
|
||||
public function category()
|
||||
public function category($id = null)
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
if (Session::get('privilege') != 1) {
|
||||
@ -229,7 +227,19 @@ class Posts
|
||||
die();
|
||||
}
|
||||
$categories = [];
|
||||
$get_categories = $this->model->showAll([], 'kategori');
|
||||
$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');
|
||||
$method = 'post';
|
||||
}
|
||||
|
||||
if ($get_categories) {
|
||||
if (!array_key_exists(0, $get_categories)) {
|
||||
@ -241,7 +251,9 @@ class Posts
|
||||
|
||||
View::render('Data/kategori.html', [
|
||||
'categories' => $categories,
|
||||
'token' => Token::generate()
|
||||
'token' => Token::generate(),
|
||||
'method' => $method,
|
||||
'value' => $values
|
||||
]);
|
||||
} else {
|
||||
throw new \Exception("Page not found", 404);
|
||||
@ -293,7 +305,7 @@ class Posts
|
||||
|
||||
$this->model->update($args, $args['id'], $table);
|
||||
|
||||
Session::flash('info', 'Data berhasil diaktifkan');
|
||||
Session::flash('info', 'Update berhasil');
|
||||
Redirect::to('/posts/category');
|
||||
die();
|
||||
}
|
||||
|
@ -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 %}
|
@ -5,7 +5,7 @@
|
||||
{% block body %}
|
||||
<main class="documentation">
|
||||
<section>
|
||||
<h1>Kategori</h1>
|
||||
<h1><a href="/posts/category">Kategori</a></h1>
|
||||
|
||||
<div class="flex two-600 full grow">
|
||||
|
||||
@ -17,29 +17,34 @@
|
||||
<label for="category">Nama</label>
|
||||
</div>
|
||||
<div class="two-third-600 full">
|
||||
<input type="text" name="category">
|
||||
<input type="text" name="category" value="{{ value.category }}">
|
||||
</div>
|
||||
|
||||
<div class="third-600 full">
|
||||
<label for="background">Background</label>
|
||||
</div>
|
||||
<div class="two-third-600 full">
|
||||
<input type="color" name="background">
|
||||
<input type="color" name="background" value="{{ value.background }}">
|
||||
</div>
|
||||
|
||||
<div class="third-600 full">
|
||||
<label for="foreground">Teks</label>
|
||||
</div>
|
||||
<div class="two-third-600 full">
|
||||
<input type="color" name="foreground">
|
||||
<input type="color" name="foreground" value="{{ value.foreground }}">
|
||||
</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="_token" value="{{ token }}">
|
||||
<button type="submit" class="pseudo full">
|
||||
{% if method == 'post' %}
|
||||
<i class="fa fa-plus fa-fw" aria-hidden="true"></i>
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
@ -58,7 +63,7 @@
|
||||
|
||||
<div class="flex two-600 full grow" style="margin:0;">
|
||||
<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>
|
||||
<span style="font-size:smaller;">Ubah</span>
|
||||
</a>
|
||||
|
Loading…
Reference in New Issue
Block a user