在旧应用程序和 Symfony2 之间桥接会话数据 [英] Bridge session data between legacy Application and Symfony2

查看:37
本文介绍了在旧应用程序和 Symfony2 之间桥接会话数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,如果在我找不到之前有人问过这个问题.我找不到我要找的答案.

Sorry if this question has been asked before I could not find it. I couldn't find the answer I was looking for.

我有一个用 Symfony2 重建的遗留应用程序,不幸的是我需要并行运行一段时间,直到我可以完成整个系统的重建.我需要让 symfony 能够访问旧会话数据才能正常工作.

I have a legacy application that I'm rebuilding with Symfony2, unfortunatly I need to run parallel for a while until I can finish rebuilding the entire system. I'm to the part where I need to have symfony be able to access the legacy session data to be able to function.

我从 Symfony 站点找到了这个:http://symfony.com/doc/current/cookbook/session/php_bridge.htmlhttp://symfony.com/doc/current/components/http_foundation/session_php_bridge.html

I found this from the Symfony site: http://symfony.com/doc/current/cookbook/session/php_bridge.html http://symfony.com/doc/current/components/http_foundation/session_php_bridge.html

但我不明白是否需要进行配置,我应该在哪里调用 session-start 以及如何从我的新应用程序访问会话数据.

But I dont understand were the configuration needs to happen and where Im supposed to call the session-start and also how to access the session data from my new application.

我是否会将 symfony 中给出的示例放在我创建的每个控制器中?

Would I be placing the example given in symfony in every controller I create?

use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;

// legacy application configures session
ini_set('session.save_handler', 'files');
ini_set('session.save_path', '/tmp');
session_start();

// Get Symfony to interface with this existing session
$session = new Session(new PhpBridgeSessionStorage());

// symfony will now interface with the existing PHP session
$session->start();

似乎应该有一种方法可以集中它.

Seems like there should be a way to centralize it.

更新手册给出了一个例子,但它没有说明它是否应该放在某个地方的控制器、服务、实体或配置中.

UPDATE The manual gives an example but It doesn't say if its supposed to go in a controller, service, entity, or config somewhere.

我尝试在控制器中使用示例代码,当我在 $session 上执行 print_r 时,我看不到任何旧会话数据.

I tried using the example code in a controller and when I do a print_r on the $session I don't see any legacy session data.

**

提前致谢.

推荐答案

您所看到的是 symfony 使用的组件的示例代码.Symfonys 会话从 app/config.yml 中设置的参数初始化.组件说明仅适用于您在 symfony 之外使用组件的情况.你想要的就是第一个.但是使用:

What you are looking at there is sample code for the Component that symfony uses. Symfonys session is initialized from parameters set in to app/config.yml. The component instructions are only if you are using the component outside of symfony. The one you want is the first one. However using:

#app/config.yml
framework:
    session:
        storage_id: session.storage.php_bridge
        handler_id: session.handler.native_file

如果您在其他应用程序中包含 symfony,其中 session_start() 在 symfony 被实例化之前被调用,则可以使用.我还没有测试过这个,但它可能仍然可以让它们并行运行,但你最终可能不得不对会话处理程序进行一些自定义.

Is meant to be used if you are including symfony within your other application where session_start() is being called before symfony is instantiated. I havent tested this but it may still work having them run in parallel but you may end up having to do some customization to the session handler.

也许考虑使用 pdo 会话处理程序:http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html

Maybe look into using a pdo session handler: http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html

这篇关于在旧应用程序和 Symfony2 之间桥接会话数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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