Passing Session to TWIG template

前端 未结 4 2020
春和景丽
春和景丽 2021-01-03 09:06

i have a problem when i want to get $_SESSION[\'session\']; in twig template using slim micro Framework.

this is my code :



        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 09:53

    This how I was able to achieve it with Slim Framework ver3

    $container['view'] = function ($container) {
    
        ...
        $view = new Twig($settings['view']['template_path'], $settings['view']['twig']);
        $view->getEnvironment()->addGlobal('session', $_SESSION);
    
        ...
    
        return $view;
    };
    

    And then access the session in the Twig template like

提交回复
热议问题