[英]Symfony2 store variables in session
first of all, i'm working with symfony 2.0.20... and I have problems with the session. 首先,我正在使用symfony 2.0.20。 I'm doing that:
我正在这样做:
Get the session service: 获取会话服务:
$session = $this->get('session');
Save the vars (obviously criteria have some value): 保存变量(显然,条件具有某些价值):
$session->set('criteria', $criteria);
And I get the var like this: 我得到这样的var:
$criteria = $session->get('criteria');
But, I never no data inside... any idea? 但是,我从不里面没有任何数据。 And, in the chrome/firefox inspector I don't see anything and the "var_dump" the same...
而且,在chrome / firefox检查器中,我什么也看不到,“ var_dump”也一样。
Any help will be appreciated 任何帮助将不胜感激
Roger 罗杰
did you start your session $session = new Session(); 您是否开始了会话$ session = new Session(); $session->start();
$ session-> start();
Make sure to use
确保
use
use Symfony\Component\HttpFoundation\Request;
This is how I start a session in Symfony2 这就是我在Symfony2中开始会话的方式
$session = $request->getSession();
This is how i set it 这是我设置的方式
$session->set('products', $products);
This is how i get it 这就是我的方法
$session->get('products')
and in my config.yml 并在我的config.yml中
framework:
session:
cookie_lifetime: 86400
gc_maxlifetime: 1800
I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.