php - SLIM Separating out route from function using TWIG -


if want separate out route function best way still need use($app,$twig)

$app->get('/app(/:date(/:time))', function ($date = null,$time = null) use ($app,$twig)     {            //do stuff using twig });   $app->run(); 

new route, function function app(...

$app->get('/app(/:date(/:time))', 'app'); 

edit 1 - next try using class give `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);      //  data using date time          $template = $twig->loadtemplate('template.php');             echo $template->render(array(             ........             ));     } } 

$appfunc = function () use ($app, $twig) ... $app->get(..., $appfunc); 

or:

class actions {      protected $app, $twig;      public function __construct($app, $twig) {         $this->app  = $app;         $this->twig = $twig;     }      public function app() ...  }  $actions = new actions($app, $twig);  $app->get(..., [$actions, 'app']); 

or:

function app($app, $twig) {     return function () use ($app, $twig) ... }  $app->get(..., app($app, $twig)); 

or coughglobalcough.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -