问题描述
我正在开发一个使用Symfony 2.8的旧项目。
我在本地开发 ,并且在树枝上可以正确使用{{app.user.username}}
或其他类似{{app.session...}}
的东西。
当我将其部署在临时环境中时,这些值始终为空。
然后,如果我将其部署在 production 中,则全局app
变量和局部变量一样工作正常。
是否可以将登台环境配置为不初始化app
变量?我可以去哪里看看?
另外,很奇怪。如果我进行自定义,从控制器加载会话数据并将其传递给视图,也会发生相同的行为。
控制器
$session = $this->get('session');
$content = $this->render(
'blocks/logged_user_menu.html.twig',[
'access_token_sc' => $session->get('access_token')
]
);
查看
{{ access_token_sc }}
我已经读到可以看一下Security config,但似乎无济于事。
解决方法
由于@john Smith的评论,我发现这种问题与session.storage_id
文件中的config.yml
有关。就我而言,测试配置文件使用的是mock_file
,它禁止了会话行为。
在此保留说明以供参考: MockFileSessionStorage class
namespace Symfony\Component\HttpFoundation\Session\Storage;
/**
* MockFileSessionStorage is used to mock sessions for
* functional testing when done in a single PHP process.
*
* No PHP session is actually started since a session can be initialized
* and shutdown only once per PHP execution cycle and this class does
* not pollute any session related globals,including session_*() functions
* or session.* PHP ini directives.
*
* @author Drak <drak@zikula.org>
*/
class MockFileSessionStorage extends MockArraySessionStorage
{ ...