【问题标题】:Phalcon 2 output flash with twig template带有树枝模板的 Phalcon 2 输出闪光灯
【发布时间】:2016-10-18 15:59:36
【问题描述】:

我使用 twig 作为模板引擎,效果很好,但我在输出 flash 消息时遇到了问题。这些都没有显示任何东西。

{{ this.flash.output() }}

只有 {{ content }} 有效,但它也会输出通知和 php 警告消息。

这就是我设置闪光灯的方式

$di->set('flash', function () {
    $flash = new FlashDirect([
      //tie in with twitter bootstrap classes
      'error'     => 'alert alert-danger',
      'success'   => 'alert alert-success',
      'notice'    => 'alert alert-info',
      'warning'   => 'alert alert-warning'
    ]);

    return $flash;
});

这就是我将消息传递到闪存的方式

$this->flash->error('Please use the link sent to you by email');

任何帮助将不胜感激。

【问题讨论】:

  • 能够使用 {{ content }} 而不是 {{ flash.output() }} 修复它

标签: twig phalcon


【解决方案1】:

您在 Volt 中输出 flash 消息,例如:(没有 this

{{ flash.output() }}

然后你在 PHP 中输​​出 flash 消息,例如:

<?php echo $this->flash->output(); ?>

【讨论】:

  • 是的,但是我用的是twig模板引擎,{{ flash.output() }}不起作用,在twig中你不能直接使用php代码
  • 你是如何使用这个树枝模板的?向我们展示您的 phalcon 引擎类。只要 twig 引擎从这个答案扩展 Injectable 代码就应该可以正常工作了。
【解决方案2】:

你在使用重定向吗?

如果是这样,您需要 flashSession。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-26
    • 2012-07-27
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 2014-01-02
    • 2013-08-07
    • 2022-01-02
    相关资源
    最近更新 更多