From b704e2f1a720ceaf23eee182a1f92df7ad7e8182 Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Putra Date: Thu, 28 Sep 2017 11:43:28 +0700 Subject: [PATCH] Updated mithril to do as it has to do --- App/Controllers/Api.php | 47 ++++++++++++++++++++----------------- App/Views/Data/mithril.html | 14 +++++------ 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/App/Controllers/Api.php b/App/Controllers/Api.php index 5c9d419..a37b3eb 100644 --- a/App/Controllers/Api.php +++ b/App/Controllers/Api.php @@ -1,31 +1,34 @@ [ - [ - 'id' => 1, - 'judul' => 'post_1', - 'status' => 1 - ], - [ - 'id' => 2, - 'judul' => 'post_2', - 'status' => 0 - ], - [ - 'id' => 3, - 'judul' => 'post_3', - 'status' => 2 - ] - ] - ]; + private $model; + + public function __construct() { + $this->model = new Post(); + } + + public function posts() { + $get = []; + $get['count'] = 0; + $get['data'] = $this->model->showJoin([ + ['pengumuman.status', '=', 1] + ]); + + if (array_key_exists(0, $get['data']) == false) { + $temp_data = $get['data']; + unset($get['data']); + $get['data'][] = $temp_data; + $temp_data = []; + } + + if ($get['data'] != false) { + $get['count'] = count($get['data']); + } - $get['count'] = count($get['data']); header('Content-Type: application/json'); echo json_encode($get); } diff --git a/App/Views/Data/mithril.html b/App/Views/Data/mithril.html index c7ab863..627836a 100644 --- a/App/Views/Data/mithril.html +++ b/App/Views/Data/mithril.html @@ -7,13 +7,14 @@ {% endblock %}