Fix categories issues

This commit is contained in:
Gregorio Chiko Putra 2017-09-11 09:20:27 +07:00
parent aec3b73730
commit eeaa2427a0

View File

@ -112,7 +112,15 @@ class Posts
$date = new \DateTime(); $date = new \DateTime();
$now = $date->format("Y-m-d"); $now = $date->format("Y-m-d");
$categories = $this->model->showAll([], 'kategori'); $get_categories = $this->model->showAll([
['status', '=', 1]
], 'kategori');
if (array_key_exists(0, $get_categories)) {
$categories = $get_categories;
} else {
$categories[] = $get_categories;
}
$user = Session::get('userid'); $user = Session::get('userid');
@ -135,7 +143,15 @@ class Posts
$id = implode('', $id); $id = implode('', $id);
} }
$categories = $this->model->showAll([], 'kategori'); $get_categories = $this->model->showAll([
['status', '=', 1]
], 'kategori');
if (array_key_exists(0, $get_categories)) {
$categories = $get_categories;
} else {
$categories[] = $get_categories;
}
$post = $this->model->showAll([ $post = $this->model->showAll([
['id', '=', $id] ['id', '=', $id]
@ -182,7 +198,14 @@ class Posts
public function category() public function category()
{ {
if (Session::exists('userid')) { if (Session::exists('userid')) {
$categories = $this->model->showAll([], 'kategori'); $categories = [];
$get_categories = $this->model->showAll([], 'kategori');
if (!array_key_exists(0, $get_categories)) {
$categories[] = $get_categories;
} else {
$categories = $get_categories;
}
View::render('Data/kategori.html', [ View::render('Data/kategori.html', [
'categories' => $categories, 'categories' => $categories,
@ -204,7 +227,7 @@ class Posts
foreach ($args as $value) { foreach ($args as $value) {
if ($value == '') { if ($value == '') {
Session::flash('info', 'Semua data harus diisi.'); Session::flash('info', 'Semua data harus diisi.');
if ($table) { if (isset($table)) {
Redirect::to("/posts/category"); Redirect::to("/posts/category");
} else { } else {
Redirect::to('/posts/entry'); Redirect::to('/posts/entry');
@ -213,7 +236,11 @@ class Posts
} }
} }
$args['content'] = htmlspecialchars($args['content']); if (isset($args['content'])) {
$args['content'] = htmlspecialchars($args['content']);
} elseif (isset($args['category'])) {
$args['category'] = htmlspecialchars($args['category']);
}
if (isset($table)) { if (isset($table)) {
if ($this->model->entry($args, $table)) { if ($this->model->entry($args, $table)) {