Skip to content

Instantly share code, notes, and snippets.

@hndr91
Created January 28, 2016 13:41
Show Gist options
  • Save hndr91/8fc591c350ec818c8a05 to your computer and use it in GitHub Desktop.
Save hndr91/8fc591c350ec818c8a05 to your computer and use it in GitHub Desktop.
Index.php with View Configuration, Slim Framework
<?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