Container-> get('route')方法返回什么以及为什么 它用于细长的树枝延伸
答案 0 :(得分:0)
Slim Twig扩展名需要router
(不是路由)实例用于path_for()
和base_url()
之类的自定义模板函数。
示例:
// Register Twig View helper
$container['view'] = function ($c) {
$view = new \Slim\Views\Twig('path/to/templates', [
'cache' => 'path/to/cache'
]);
// Instantiate and add Slim specific extension
$router = $c->get('router');
$uri = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER));
$view->addExtension(new \Slim\Views\TwigExtension($router, $uri));
return $view;
};