Receive data from database and pass to html using twig
This commit is contained in:
@@ -8,7 +8,8 @@ class Home
|
||||
public function index()
|
||||
{
|
||||
// echo "This is index of home"; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
|
||||
View::render('Data/pengumuman.html');
|
||||
$posts = new Posts();
|
||||
$posts->index();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,36 +2,51 @@
|
||||
namespace App\Controllers;
|
||||
|
||||
use \Core\View;
|
||||
use App\Models\Post;
|
||||
|
||||
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');
|
||||
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');
|
||||
View::render('Data/entry_pengumuman.html', [
|
||||
'categories' => $categories
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function edit($id = null)
|
||||
{
|
||||
if ($id) {
|
||||
$posts = $this->model->showSingle($id);
|
||||
// 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' => 4,
|
||||
'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
|
||||
'created_at' => '2017-05-10 10:00',
|
||||
'creator' => '5',
|
||||
'edited_at' => '2017-08-10 10:00',
|
||||
'editor' => '8'
|
||||
'category' => $posts['category'],
|
||||
'content' => $posts['content'],
|
||||
'created_at' => $posts['created_at'],
|
||||
'creator' => $posts['creator'],
|
||||
'edited_at' => $posts['edited_at'],
|
||||
'editor' => $posts['editor']
|
||||
]
|
||||
);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user