lepisi-pengumuman/App/Controllers/Posts.php
Gregorio Chiko Putra c64064321e - Function to store and get worked good
- Token works great
- Session works great
2017-09-05 10:01:27 +07:00

69 lines
1.8 KiB
PHP

<?php
namespace App\Controllers;
use \Core\View;
use App\Models\Post;
use \Core\Token;
use \Core\Session;
class Posts
{
private $model;
public function __construct()
{
$this->model = new Post();
}
public function index()
{
$posts = $this->model->showAll();
// echo "This is index of posts."; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
View::render('Data/pengumuman.html', [
'posts' => $posts
]);
return true;
}
public function entry()
{
$categories = $this->model->showCategories();
// 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,
'token' => Token::generate()
]);
return true;
}
public function edit($id = [])
{
if ($id) {
$id = implode('', $id);
$posts = $this->model->showSingle($id);
$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',
[
'posts' => $posts,
'categories' => $categories,
'token' => Token::generate()
]
);
return true;
}
return false;
}
// Methods
public function post($args = [])
{
$table = 'pengumuman';
if ($this->model->entry($table, $args)) {
Session::flash('info', 'Data successfuly uploaded');
return $this->index();
}
}
}