diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index 246c97a..b82133c 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -4,6 +4,7 @@ namespace App\Controllers; use \Core\View; use App\Models\Post; use \Core\Token; +use \Core\Session; class Posts { @@ -27,34 +28,26 @@ class Posts public function entry() { $categories = $this->model->showCategories(); - $date = new \DateTime(); - $timestamp = $date->format('Y/m/d H:i:s'); // echo "You can entry new data here."; // Nanti di replace sama twig view ke App\Views\Data\entry_pengumuman.html View::render('Data/entry_pengumuman.html', [ 'categories' => $categories, - 'timestamp' => $timestamp, 'token' => Token::generate() ]); return true; } - public function edit($id = null) + public function edit($id = []) { if ($id) { + $id = implode('', $id); $posts = $this->model->showSingle($id); - $date = new \DateTime(); - $timestamp = $date->format('Y/m/d H:i:s'); + $categories = $this->model->showCategories(); // echo "You can edit exists data with id $id here"; // Nanti di replace sama twig view ke App\Views\Data\edit_pengumuman.html View::render( 'Data/edit_pengumuman.html', [ - 'category' => $posts['category'], - 'content' => $posts['content'], - 'created_at' => $posts['created_at'], - 'creator' => $posts['creator'], - 'edited_at' => $posts['edited_at'], - 'editor' => $posts['editor'], - 'timestamp' => $timestamp, + 'posts' => $posts, + 'categories' => $categories, 'token' => Token::generate() ] ); @@ -62,4 +55,14 @@ class Posts } return false; } + + // Methods + public function post($args = []) + { + $table = 'pengumuman'; + if ($this->model->entry($table, $args)) { + Session::flash('info', 'Data successfuly uploaded'); + return $this->index(); + } + } } diff --git a/App/Views/Data/edit_pengumuman.html b/App/Views/Data/edit_pengumuman.html index e5a6c83..4780e3d 100644 --- a/App/Views/Data/edit_pengumuman.html +++ b/App/Views/Data/edit_pengumuman.html @@ -4,43 +4,44 @@ {% block body %}
-

Pengumuman 1

+ {% for post in posts %} +

Pengumuman {{ post.id }}


- +
- +
- +
- +
- + - + + {% endfor %} diff --git a/App/Views/Data/entry_pengumuman.html b/App/Views/Data/entry_pengumuman.html index 7c7e7b2..547d4c0 100644 --- a/App/Views/Data/entry_pengumuman.html +++ b/App/Views/Data/entry_pengumuman.html @@ -6,8 +6,8 @@

Tambah Pengumuman

- - {% for cat in categories %} {% endfor %} @@ -15,20 +15,27 @@
- - + + + +
+ + + + + - + - +
- +
{% endblock %} diff --git a/Core/Router.php b/Core/Router.php index 062c328..a67c9f9 100644 --- a/Core/Router.php +++ b/Core/Router.php @@ -66,11 +66,29 @@ class Router $action = $this->convertToCamelCaps($action); if (is_callable([$object, $action])) { - if (array_key_exists('id', $this->params)) { - $var = $this->params['id']; - return $object->$action($var); + // Check if there's input to the current page + if (Input::exists('post')) { + $var = $_POST; + // Check the token + if (Token::check($var['_token'])) { + // Get the method + $action = $var['_method']; + } else { + // Token invalid + $flash = Session::flash('info', 'Token invalid, try again'); + die($flash); + } + unset($var['_token']); + unset($var['_method']); + } + if (array_key_exists('id', $this->params)) { + $var[] = $this->params['id']; + } + if (isset($var)) { + return $object->$action($var); + } else { + return $object->$action(); } - return $object->$action(); } } } diff --git a/public/index.php b/public/index.php index 88d3a34..7e550af 100644 --- a/public/index.php +++ b/public/index.php @@ -1,7 +1,13 @@ "; +} + $router = new Core\Router(); $router->add('', ['controller' => 'posts', 'action' => 'index']);