dongziya9863 2014-04-01 13:59
浏览 49
已采纳

Symfony如何隔离应用程序的SESSION值?

I try to understand how Symfony isolate SESSION values of application. I create two files:

// test.php
session_start();
$_SESSION['aaa'] = 111;
var_dump($_SESSION);

and

// test2.php
session_start();
var_dump($_SESSION);

So when I call http://localhost/test.php and then call http://localhost/test2.php, I get same SESSION in both files:

array(1) { ["aaa"]=> int(111) }

But when I add to the end of symfony front controller app_dev.php next code:

var_dump($_SESSION);

and try to call http://localhost/app_dev.php - I get only Symfony session

array(3) { ["_sf2_attributes"]=> &array(0) { } ["_sf2_flashes"]=> &array(0) { } ["_sf2_meta"]=> &array(3) { ["u"]=> int(1396360435) ["c"]=> int(1396360433) ["l"]=> string(1) "0" } }

and I don't get access to the array(1) { ["aaa"]=> int(111) } value, that I expected.

Why? And how can i do mutual session values with this 3 files?

  • 写回答

1条回答 默认 最新

  • doufei8250 2014-04-01 14:23
    关注

    Symfony use NativeFileSessionHandler as default, and all data in this storage will be not expected in another systems.

    As solution, you can create native session handler as service (Class already exists in Symfony/HttpFoundation package) and set this handler to configuration framework.session.handler_id

    For more information, you can see in docs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?