当我尝试在树枝中添加扩展添加全局
$view = new \Slim\Views\Twig($settings['template_path'], [
'debug' => $settings['debug'],
'cache' => $settings['cache_path']
]);
// Add extensions
$view->addExtension(new \Slim\Views\TwigExtension(
$c['router'],
$c['request']->getUri()
));
$view->addExtension(new \Core\TwigFunction());
$view->addExtension(new Twig_Extension_Debug());
$view = new Twig_Environment();;
$view->addGlobal('session', $_SESSION);
我收到:
调用未定义的方法Twig_Environment :: offsetSet()
答案 0 :(得分:2)
在第
行$view = new Twig_Environment();
您正在覆盖$view
变量。删除该行应解决问题,因为slim/twig-view
为您设置了Twig环境。