带 Flashbag 的 Symfony2 PDO 会话 [英] Symfony2 PDO Session with Flashbag

查看:27
本文介绍了带 Flashbag 的 Symfony2 PDO 会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 session.handler.pdo 中使用 Symfony 2.3.1(这个问题也出现在 2.2 中),但是当我像这样添加一个 flash bag 消息时:

I'm using Symfony 2.3.1 (this issue was also present in 2.2) with session.handler.pdo, but when I add a flash bag message like so:

$this->get('session')->getFlashBag()->add(
     'success', "Your message has been sent."
);                

return $this->redirect($this->generateUrl('home'));

重定向后它不会显示在主页上,直到我按刷新,然后它才会显示.所以它需要显示 2 个请求.如果我将会话存储改回本机,这个问题就消失了.任何想法为什么会发生这种情况?

It does not show on the home page after the redirect until I press refresh, then it shows up. So its taking 2 requests to be displayed. If I change the session storage back to native this problem is gone. Any ideas why this is happening?

我使用以下内容在 Twig 中打印消息

I use the following to print the messages in Twig

{% for flashMessage in app.session.flashbag.get('success') %}
     {{flashMessage}}
{% endfor %} 

和我的服务是一样的文档如下:

and my services is the same as the documentation as follows:

services:
    pdo:
        class: PDO
        arguments:
            dsn:      "mysql:dbname=%database_name%"
            user:     %database_user%
            password: %database_password%
        calls:
            - [setAttribute, [3, 2]] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION

    session.handler.pdo:
        class:     Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
        arguments: ["@pdo", %pdo.db_options%]

推荐答案

我在使用 swiftmailer 时遇到了同样的问题,我得到了一个快速解决方案.

I've the same problem when using swiftmailer, and I got a quickfix for this problem.

如果您在此操作中使用 SwiftMailer,请尝试删除配置文件中的 spool 行.

If you are using SwiftMailer in this action, try to remove the spool line in your config file.

这不是解决问题的最佳方法,但确实有效.

Thats not the best way to fix it, but it works.

仍在此处工作并思考更好的解决方案...

Still working and thinking in a better solution here...

这篇关于带 Flashbag 的 Symfony2 PDO 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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