If I want to separate out the route from the function what is the best way as I still need to use($app,$twig)
$app->get('/app(/:date(/:time))', function ($date = null,$time = null) use ($app,$twig) {
//do some stuff using TWIG
});
$app->run();
new route, function function app(...
$app->get('/app(/:date(/:time))', 'app');
Edit 1 - Next try using a class give a `Undefined variable: twig'
$actions = new Actions($app, $twig);
$app->get('/app(/:date(/:time))', [$actions, 'app']);
$app->run();
class Actions {
protected $app, $twig;
public function __construct($app, $twig) {
$this->app = $app;
$this->twig = $twig;
}
public function app($date = null,$time = null) {
// print_r($:date);
// get some data using date time
$template = $twig->loadTemplate('template.php');
echo $template->render(array(
........
));
}
}