2017-01-27 84 views
1

當我嘗試添加添加擴展全球在樹枝如何添加擴展加入全球在樹枝

$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()

回答

2

在線

$view = new Twig_Environment(); 

您正在覆蓋$view變量。刪除該行應該解決問題,因爲slim/twig-view爲您設置了Twig環境。

+0

不能正常工作,我的code over variabel $ view ?, –

+1

您能詳細說明哪些方法無效嗎?添加$ view-> addGlobal('session',$ _SESSION)後添加 – meun5

+0

;代碼doesnt'n工作 –