dongyi9330 2016-09-30 07:53 采纳率: 100%
浏览 58

Symfony 2获得当前会话时间

I'm starting session like this:

$session = new Session();
$session->start();

Browsing documentation I found the method that returns lifetime of the session. Default Symfony 2.3 session time is 3600s. Is there a method that will return a current session time? (for instance session lasts for 10 minutes so I will get 600s). I haven't found anything like this in the documentation.

Or is there a way to manually count this time and carry this value through pages during the session?

  • 写回答

1条回答 默认 最新

  • dqybeh2884 2016-09-30 09:56
    关注

    Sure you can.

        $session = $this->get('session'); //you can get session from service container. no need for creating new instance.
    
    // MetadataBag is what you're looking for
    $sessionBag = $session->getMetadataBag();
    
    // Here we go...
    var_dump($sessionBag->getCreated());
    var_dump($sessionBag->getLastUsed());
    

    You may want to use created oflastUsed depending or your needs. created is when the session was initialized (first page request of user), while lastUsed is the latest of course. But since you're saying something about session lifetime you may want to use the second one, because that's the point of time where the lifetime is relative to.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错