Symfony 2.8|Twig|app.user和app.session在stage env中为null,在本地和产品



我正在开发一个使用Symfony 2.8的旧项目。

我在本地开发,在Twig中我可以正确使用{{app.user.username}}或其他类似的{{app.session...}}。当我在暂存环境中部署它时,这些值始终为空。然后,如果我将其部署在生产中,则全局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 }}

我读到我可以查看安全配置,但似乎没有帮助。

感谢@john Smith的评论,我发现这种问题与config.yml文件中的session.storage_id有关。在我的案例中,测试配置文件使用了禁止会话行为的mock_file

在此留下解释以供参考:MockFileSessionStorage类

namespace SymfonyComponentHttpFoundationSessionStorage;
/**
* 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
{ ...

相关内容

最新更新