如何在控制器中设置会话的过期时间? [英] How to set expiration time to session in the controller?

查看:45
本文介绍了如何在控制器中设置会话的过期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在控制器中设置一个过期时间为 5 分钟的会话.我该怎么做?我需要类似的东西:

I need to set a session with expiration time of 5min in controller. How do i do it? I need something like:

$this->container->get('session')->set('mysession', 'value', 'expiration');

以 symfony2 的方式?

in symfony2 way?

谢谢!

推荐答案

此功能最近.您可以更新到此提交或补丁.从代码看来,您可以通过以下方式设置到期时间,

This feature is added recently. You can update to this commit or patch. From the code it seems you can set expiry time by following way,

$this->container->get('session')->getMetadataBag()->stampNew(300);

这篇关于如何在控制器中设置会话的过期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆