From dc2064b09a35882a34f5296f76a4c5b3ba2238a6 Mon Sep 17 00:00:00 2001 From: Dian Date: Tue, 5 Oct 2021 18:22:57 +0800 Subject: [PATCH 1/8] udpate readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf58100..0dfdc68 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ $query_builder = TRUE; $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', - 'username' => 'root', // <- sesuaikan dengan username mysql-mu - 'password' => '', // <- jika user mysql-mu menggunakan password, silahkan isi ini + 'username' => 'root', // <- sesuaikan dengan username mysql + 'password' => '', // <- isi dengan password user mysql 'database' => 'beritacoding', //<- sesuaikan nama database dengan yang kamu buat 'dbdriver' => 'mysqli', 'dbprefix' => '', From 440dfb4c9274a2776d6c7a43ae42ec9e3f765dc5 Mon Sep 17 00:00:00 2001 From: Dian Date: Wed, 16 Feb 2022 12:27:00 +0800 Subject: [PATCH 2/8] fitur pencarian untuk halaman public --- application/controllers/Search.php | 15 +++++++++ application/models/Article_model.php | 11 ++++++ application/views/_partials/navbar.php | 1 + application/views/search.php | 46 ++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 application/controllers/Search.php create mode 100644 application/views/search.php diff --git a/application/controllers/Search.php b/application/controllers/Search.php new file mode 100644 index 0000000..db10c37 --- /dev/null +++ b/application/controllers/Search.php @@ -0,0 +1,15 @@ +input->get('keyword'); + $this->load->model('article_model'); + + $data['search_result'] = $this->article_model->search($data['keyword']); + + $this->load->view('search.php', $data); + } +} diff --git a/application/models/Article_model.php b/application/models/Article_model.php index 79b56be..2e0be05 100644 --- a/application/models/Article_model.php +++ b/application/models/Article_model.php @@ -68,6 +68,17 @@ public function find($id) return $query->row(); } + public function search($keyword) + { + if(!$keyword){ + return null; + } + $this->db->like('title', $keyword); + $this->db->or_like('content', $keyword); + $query = $this->db->get($this->_table); + return $query->result(); + } + public function insert($article) { return $this->db->insert($this->_table, $article); diff --git a/application/views/_partials/navbar.php b/application/views/_partials/navbar.php index a521363..af6e282 100644 --- a/application/views/_partials/navbar.php +++ b/application/views/_partials/navbar.php @@ -1,6 +1,7 @@