【问题标题】:Flash message doesn't work in element or layoutFlash 消息在元素或布局中不起作用
【发布时间】:2016-12-17 14:40:12
【问题描述】:

我无法让 Flash 消息出现在元素或布局中。但是,它在模板中可以正常工作。

我的元素、布局和模板中有以下代码:

<?= $this->Flash->render();?>

当我创建错误时,从视图调用时它显示正常,但从元素或我的布局文件中不起作用。

这个想法是在表单顶部加载 Flash 消息,该表单是使用我的布局左侧导航中的元素生成的。

【问题讨论】:

    标签: cakephp cakephp-3.0


    【解决方案1】:

    似乎调用多个Flash-&gt;render() 会清除其他后续调用的会话。

    我只需要找出限制调用哪个Flash-&gt;render() 的最佳方法。例如,将 Flash-&gt;render() 包装在我的元素中的 if 语句中。还有可能对我正在调查的个别 Flash 消息进行密钥处理。

    我的解决方案

    设置闪光灯:

    $this->Flash->error(__('Invalid credentials, try again'), ['key' => 'element']);
    

    在我的元素中:

    <?= $this->Flash->render('element')?>
    

    【讨论】:

    猜你喜欢
    • 2017-03-28
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    相关资源
    最近更新 更多