Symfony2,symfony1.4和$ _SESSION

时间:2012-12-23 19:34:27

标签: php session symfony-1.4 session-variables symfony-2.1

我有一个项目,我想使用Symfony2.1symfony 1.4,当然我需要与会话共享它们之间的一些数据,但我不明白为什么会话不可见它们之间。 例如:

在symfony1过滤器中,我有:

echo session_id().'<br>';
echo session_name();
$_SESSION['test_s1'] = '123';
var_dump($_SESSION);

结果是:

d30irfcdhjio27uiqd7a52blv7
symfony
array (size=6)
  'symfony/user/sfUser/lastRequest' => int 1356289903
  'symfony/user/sfUser/authenticated' => boolean false
  'symfony/user/sfUser/credentials' => 
    array (size=0)
      empty
  'symfony/user/sfUser/attributes' => 
    array (size=0)
      empty
  'symfony/user/sfUser/culture' => string 'en_US' (length=5)
  'test_s1' => string '123' (length=3)

所以,一切都很好。

在Symfony2控制器中,我有:

echo session_id() . '<br>';
echo session_name();
$_SESSION['test_s2'] = '123';
$session->set('test_s2_second', '321');
var_dump($_SESSION);
die;

结果:

d30irfcdhjio27uiqd7a52blv7
symfony
array (size=4)
  '_sf2_attributes' => &
    array (size=4)
      'razvan' => string 'test' (length=4)
      '_security_secured_area' => string 'C:74:"Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken":777:{a:3:{i:0;N;i:1;s:12:"secured_area";i:2;s:728:"a:4:{i:0;O:41:"Symfony\Component\Security\Core\User\User":7:{s:51:"?Symfony\Component\Security\Core\User\User?username";s:6:"user";s:51:"?Symfony\Component\Security\Core\User\User?password";s:8:"userpass";s:50:"?Symfony\Component\Security\Core\User\User?enabled";b:1;s:60:"?Symfony\Component\Security\Core\User\User?accountNonExpired";b:1;s:64:"?Symfony\Component\Security\Core'... (length=865)
      'search_form' => string '' (length=0)
      'test_s2_second' => string '321' (length=3)
  '_sf2_flashes' => &
    array (size=0)
      empty
  '_sf2_meta' => &
    array (size=3)
      'u' => int 1356289889
      'c' => int 1356287606
      'l' => string '0' (length=1)
  'test_s2' => string '123' (length=3)

所以,session_id和session_name是相同的,但我看不到我在Symfony2中通过symfony1设置的会话的键/值,即使我使用$ _SESSION也是如此。

背后的架构更复杂,我试图只暴露主要问题。

那么,任何想法如何从Symfony2.1中将一些变量设置为会话并在symfony 1.4页面中可见?

(我用Symfony2.0做了同样的伎俩并且技巧有效)。

1 个答案:

答案 0 :(得分:0)

docs中有关于该主题的食谱文章。以下是theodo的博客文章(他们的个人资料是将symfony1应用程序移植到Symfony2)关于how to share the sessions using memcache,他们也有一个bundle (TheodoEvolutionSessionBundle)。关于将遗留应用程序移植到Symfony2的这个问题和其他问题,还有video