会话怎么在Symfony2中使用

  

会话怎么在Symfony2中使用?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

Symfony自带有会话的方法,以前老版2.2本及以前的会议用法是

session 美元;=,$ this→getRequest ()→getSession ();   美元会话→设置(& # 39;foo # 39;,, & # 39;酒吧# 39;);   foobar 美元;=,会话→美元得到(& # 39;foobar # 39;);

后来Symfony2.3开始$ this→getRequest()方法被废弃,会话的使用方法就变成了

use  Symfony \ HttpFoundation \ \组件请求;   public  function  indexAction (Request 美元请求)   {   时间=美元才能session 美元请求→getSession ();//才能,store  an  attribute  for  reuse  during  a  later  user 请求   美元才能会话→设置(& # 39;foo # 39;,, & # 39;酒吧# 39;);//才能,get 从而attribute  set  by  another  controller 拷贝another 请求   时间=美元才能foobar 会话→美元得到(& # 39;foobar # 39;);//才能,use  a  default  value  if 从而attribute 并# 39;t 存在   时间=美元才能filters 会话→美元得到(& # 39;过滤器# 39;,,数组());   }

看完上述内容,你们掌握会话怎么在Symfony2中使用的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!

会话怎么在Symfony2中使用