为什么Symfony2中的会话数据为空以及如何访问它? [英] Why is session data empty in Symfony2 and how to access it?

查看:27
本文介绍了为什么Symfony2中的会话数据为空以及如何访问它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第三方 PHP 应用程序将数据存储在用户会话中(使用 PHPSESSID 的 cookie).在这个应用程序中,$_SESSION 变量包含所有这些数据.

A third-party PHP application stores data in the user's session (using a cookie for PHPSESSID). In this app, the $_SESSION variable contains all this data.

在我的 Symfony2 应用程序中,相同的 $_SESSION 只包含一些 Symfony 数据(_sf2_attributes_security_secured_area_sf2_flashes> 等),我没有看到来自其他应用的任何其他数据.

In my Symfony2 application, the same $_SESSION only contains some Symfony data (_sf2_attributes, _security_secured_area, _sf2_flashes, etc.) and I don't see any other data from the other app.

我在控制器中对 $_SESSION 变量做了一个 var_dump 来检查这个.使用 Symfony Session 对象显示相同的数据.这两个应用程序使用相同的域来存储 PHPSESSID cookie.

I did a var_dump of the $_SESSION variable in a controller to check this. Using the Symfony Session object shows the same data. The 2 apps use the same domain for storing the PHPSESSID cookie.

如何在我的 Symfony 应用程序中获取会话的所有数据?我希望在 2 个应用程序之间共享会话.

How can I get all data of the session in my Symfony app? I would like the session to be shared between the 2 applications.

推荐答案

我终于解决了这个问题.Symfony 将其会话数据存储在自己的目录中(app/cache/[environment]/sessions).所以解决办法是在config.yml中设置默认会话路径:

I finally solved the problem. Symfony stores its session data in its own directory (app/cache/[environment]/sessions). So the solution is to set the default session path in config.yml:

framework:
    session:
        save_path: ~

这将设置回默认路径(例如 Linux 上的 /var/lib/php5),并且旧应用会话数据可供 Symfony 应用使用.

This will set the default path back (for example /var/lib/php5 on Linux) and the legacy app session data is made available to the Symfony app.

这篇关于为什么Symfony2中的会话数据为空以及如何访问它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆