0

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

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.

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

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.

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.

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.

**

Thanks in advance.

3
  • 1
    So what have you tried already. Show some code and efforts. Commented Jan 26, 2015 at 18:20
  • @Paziツ That is the part of the problem. The examples given in the Symfony manual dont state which files I need to be modifying. How can I show examples if I dont know where to put them? Commented Jan 26, 2015 at 18:41
  • Have you already watch at the TheodoEvolutionSessionBundle ? this implement a "Session bridge between your legacy application and Symfony2". Support symfony1 also. See the doc. Commented Jan 27, 2015 at 8:11

1 Answer 1

2

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

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.

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the insight. does that mean I would have to put the symfony code in my legacy system for me to access the session data from the legacy system in Symfony? Thanks again!
after some playing with the configs. I was able to get to the legacy session data. Thank you for your insight. The first config is the correct one I needed. Also using $session = new Session(new PhpBridgeSessionStorage()); $session->migrate(); did the trick. thanks again!
Hi, how did you end up structuring the projects? Did you add the symfony project inside the legacy app? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.