doucheng7808 2016-08-17 19:59
浏览 22

如何在Symfony中将会话变量设置为持续30分钟

So I have created a session variable inside my edit action to prevent it from sending an email to the assigned supervisor every time the order is edited.

It seems that this works good, but instead I want it to send the mail once in a half hour to lower the amount of mails sent if a user keeps editing it in a short period of time. I also want to send a mail regardless of the half hour if the supervisor changes in the edit.

This is what I have so far;

public function editAction($id)
{
    $request = $this->getRequest();
    $session = $request->getSession();

    $order = $em->getRepository('Order')->find($id);
    $sessionName = $order . 'MailerSession';

    //do some extra stuff...

    if ($editForm->isSubmitted() && $editForm->isValid()) {
        $em = $this->getDoctrine()->getManager();
        $em->persist($order);
        $em->flush();

        if (false === $session->has($sessionName)) {
            $this->get('bss.pmod.mailer')
                    ->sendApprovalEmailMessage($object, $object->getFirstApprover(), 'first.approval.template');
        }

        $sessionData = array('order' => $order, 'supervisorId' => $order->getFirstApprover(), 'time' => new \DateTime(date('Y-m-d H:i:s')));
        $session->set($sessionName, $sessionData);

        return $this->redirectToRoute('show', array('id' => $order->getId()));
    }
}

It seems like it's working by not sending a mail again in the same session. (Please don't hesitate to mention if something is still wrong by that part.)

But I have added the supervisorId and current dateTime in the sessionData, but how can I use it to prevent emails to be sent to the same supervisor in a half hour from the edit, and still send an email to a new assigned supervisor even it is still within the half hour?

I don't yet understand sessions this well. I'm a student doing Symfony and php now for about 4 months and it is the first time I need to implement a session?

Any help please?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大