Created
January 28, 2016 13:41
-
-
Save hndr91/8fc591c350ec818c8a05 to your computer and use it in GitHub Desktop.
Index.php with View Configuration, Slim Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php' //fitur autoload composer | |
//Inisiasi Slim Framewrok | |
$app = new \Slim\Slim(array( | |
'view' => new \Slim\Views\Twig(), //set template engine to Twig engine | |
'templates.path' => './templates' //lokasi default template bisa di ganti sesuai dengan kebutuhan | |
)); | |
//home routing dengan view | |
$app->get('/', function() use($app){ | |
$app->render('template.html'); //render hasil tempalte, lokasi template harus sesuai konfigurasi pada baris ke 6 | |
}); | |
//more routing | |
$app->get('/test', function(){ | |
//set data untuk template, sehingga template dapat digunkan berulang | |
$app->view()->setData(array( | |
'title' => 'Title Data', | |
'judul' => 'Judul halaman' | |
)); | |
$app->render('template2.html'); | |
}); | |
//run Slim Framework | |
$app->run(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment