Last active
May 13, 2020 07:22
-
-
Save seitsu/4fe4725892db409e1feba175d67fb7f6 to your computer and use it in GitHub Desktop.
Skeleton app for Flight PHP 1.3.8 with Twig 3.x
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 | |
// load composer autoloader | |
require dirname(__DIR__) . '/vendor/autoload.php'; | |
// set paths for templates and cache | |
Flight::set('flight.views.path', dirname(__DIR__) . '/templates'); | |
Flight::set('flight.compiled.views.path', dirname(__DIR__) . '/var/cache'); | |
// set the view renderer to use twig. Before deploying to prod. activate the cache and | |
// set the web user allowed to read/write from/to the folder. | |
$loader = new \Twig\Loader\FilesystemLoader(Flight::get('flight.views.path')); | |
$twigConfig = array( | |
'cache' => Flight::get('flight.compiled.views.path'), | |
'cache' => false, | |
'debug' => true, | |
); | |
// sets twig as the view handler for Flight. | |
Flight::register('view', '\Twig\Environment', array($loader, $twigConfig), function($twig) { | |
$twig->addExtension(new \Twig\Extension\DebugExtension()); // add the debug extension | |
}); | |
// map the call for ease of use. | |
Flight::map('render', function($template, $data){ | |
echo Flight::view()->render($template, $data); | |
}); | |
// set default route | |
Flight::route('/*', function(){ | |
// render index.tpl (just some HTML code) | |
Flight::render('index.tpl', array()); | |
}); | |
Flight::start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment