From 6ca3e1a57a5af7d1c01049a41428877087859af8 Mon Sep 17 00:00:00 2001 From: billalxcode Date: Fri, 8 Jul 2022 16:48:02 +0700 Subject: [PATCH] Update v1.1-rev3: Add settings menu --- app/Config/Routes.php | 1 + app/Controllers/Settings.php | 36 ++++++++- app/Views/admin/settings/general.php | 106 ++++++++++++++++++--------- 3 files changed, 109 insertions(+), 34 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 42c00a5..d423426 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -80,6 +80,7 @@ $routes->group("settings", ['filter' => 'authadmin'], function ($routes) { $routes->get("", "Settings::index"); + $routes->post("save", "Settings::save"); }); }); diff --git a/app/Controllers/Settings.php b/app/Controllers/Settings.php index d66f897..8d291ae 100644 --- a/app/Controllers/Settings.php +++ b/app/Controllers/Settings.php @@ -8,8 +8,42 @@ class Settings extends BaseController { public function index() { + helper("form"); $this->context['title'] = "Kelola Pengaturan"; - + $this->context['values'] = $this->settingsModel->first(); + return $this->renderView("admin/settings/general"); } + + public function save() { + $type = $this->request->getPost('type'); + if ($type == 'general') { + $penyelenggara = $this->request->getPost("penyelenggara"); + $provinsi = $this->request->getPost("provinsi"); + $kota = $this->request->getPost("kota"); + $kecamatan = $this->request->getPost("kecamatan"); + + $penyelenggara = isset($penyelenggara) ? $penyelenggara : ""; + $provinsi = isset($provinsi) ? $provinsi : ""; + $kota = isset($kota) ? $kota : ""; + $kecamatan = isset($kecamatan) ? $kecamatan : ""; + + $data_post = [ + 'penyelenggara' => $penyelenggara, + 'provinsi' => $provinsi, + 'kota' => $kota, + 'kecamatan' => $kecamatan, + 'alamat' => '' + ]; + $settingsData = $this->settingsModel->first(); + if ($settingsData) { + $this->settingsModel->update($settingsData['id'], $data_post); + } else { + $this->settingsModel->save($data_post); + } + + $this->session->setFlashdata('success', 'Berhasil menyimpan data'); + return redirect()->back(); + } + } } diff --git a/app/Views/admin/settings/general.php b/app/Views/admin/settings/general.php index fbffba2..d0592bf 100644 --- a/app/Views/admin/settings/general.php +++ b/app/Views/admin/settings/general.php @@ -2,9 +2,17 @@ section("content"); ?>
+
+
+ getFlashdata('success')) : ?> +
+ getFlashdata('success') ?> +
+ +
+
-