Registering twig to project
This commit is contained in:
parent
81510beb10
commit
7fa99eb6d8
@ -1,17 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Controllers;
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use Core\View;
|
||||||
|
|
||||||
class Home
|
class Home
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
echo "This is index of home"; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
|
echo "This is index of home"; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
|
||||||
|
View::render('Data/pengumuman.html');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login()
|
public function login()
|
||||||
{
|
{
|
||||||
echo "You have to login"; // Nanti di replace sama twig view ke App\Views\Access\login.html
|
echo "You have to login"; // Nanti di replace sama twig view ke App\Views\Access\login.html
|
||||||
|
View::render('Access/login.html');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Controllers;
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use \Core\View;
|
||||||
|
|
||||||
class Posts
|
class Posts
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
echo "This is index of posts."; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
|
echo "This is index of posts."; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
|
||||||
|
View::render('Data/pengumuman.html');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entry()
|
public function entry()
|
||||||
{
|
{
|
||||||
echo "You can entry new data here."; // Nanti di replace sama twig view ke App\Views\Data\new_pengumuman.html
|
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');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
echo "You can edit exists data with id $id here"; // Nanti di replace sama twig view ke App\Views\Data\edit_pengumuman.html
|
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');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
Core/View.php
Normal file
17
Core/View.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace Core;
|
||||||
|
|
||||||
|
class View
|
||||||
|
{
|
||||||
|
private static $twig = null;
|
||||||
|
|
||||||
|
public static function render($template, $args = [])
|
||||||
|
{
|
||||||
|
if (self::$twig === null) {
|
||||||
|
$loader = new \Twig_Loader_Filesystem('App/Views');
|
||||||
|
$twig = new \Twig_Environment($loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $twig->render($template, $args);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user