- Function to store and get worked good

- Token works great
- Session works great
This commit is contained in:
2017-09-05 09:53:52 +07:00
parent 45dbe24da7
commit c64064321e
5 changed files with 70 additions and 35 deletions

View File

@@ -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();
}
}
}