diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index c0c8ddd..0d8f671 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -112,7 +112,15 @@ class Posts $date = new \DateTime(); $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'); @@ -135,7 +143,15 @@ class Posts $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([ ['id', '=', $id] @@ -182,7 +198,14 @@ class Posts public function category() { 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', [ 'categories' => $categories, @@ -204,7 +227,7 @@ class Posts foreach ($args as $value) { if ($value == '') { Session::flash('info', 'Semua data harus diisi.'); - if ($table) { + if (isset($table)) { Redirect::to("/posts/category"); } else { 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 ($this->model->entry($args, $table)) {