Php 使用细枝将路径与功能分离
如果我想从功能中分离出路线,最好的方法是什么,因为我仍然需要Php 使用细枝将路径与功能分离,php,twig,slim,Php,Twig,Slim,如果我想从功能中分离出路线,最好的方法是什么,因为我仍然需要使用($app,$twig) 新路线,功能功能应用程序(… $app->get('/app(/:date(/:time))', 'app'); 编辑1-下一次尝试使用类给出一个“未定义的变量:twig” $actions = new Actions($app, $twig); $app->get('/app(/:date(/:time))', [$actions, 'app']); $app->run();
使用($app,$twig)
新路线,功能功能应用程序(…
$app->get('/app(/:date(/:time))', 'app');
编辑1-下一次尝试使用类给出一个“未定义的变量: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(
........
));
}
}
或:
或:
或咳嗽global
cough
或:
或:
或咳嗽global
cough
或:
或:
或咳嗽global
cough
或:
或:
或者咳嗽
global
cough.我希望你能尽快把咳嗽分类谢谢Deceze,上面给我一个未定义变量:twig
我希望你能尽快把咳嗽分类谢谢Deceze,上面给我一个未定义变量:twig
我希望你能尽快把咳嗽分类谢谢Deceze,上面给我一个Unde罚款变量:twig
我希望您能尽快解决咳嗽问题谢谢Deceze,上面给了我一个未定义变量: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(
........
));
}
}
$appFunc = function () use ($app, $twig) ...
$app->get(..., $appFunc);
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']);
function app($app, $twig) {
return function () use ($app, $twig) ...
}
$app->get(..., app($app, $twig));