【问题标题】:How to display multiple flashmessages in the backend of OctoberCMS十月CMS后台如何显示多条flashmessage
【发布时间】:2017-12-07 11:55:27
【问题描述】:

目前 OctoberCMS 仅显示每种类型(成功、错误等)的第一个 flash message。在 github 上也有一个 issue 关于它。

我需要显示所有消息。一个非常简单的用例是删除列表中的记录。如果某些记录未被删除,则应显示有关它们的错误消息,并显示成功消息,说明哪些记录已成功删除。

有人可以建议解决此问题的方法,以便显示多条消息吗?

【问题讨论】:

    标签: octobercms


    【解决方案1】:

    一种解决方案是通过用类似这样的方式(使用Noty)覆盖flash_messages.htm 中的默认布局来替换原生通知功能

        <?php 
        $types = ['success', 'info', 'warning', 'error'];
        ?>
    
        <script type="text/javascript">
            <?php 
            foreach ($types as $type) {
                foreach (Flash::$type() as $message): ?>
                    new Noty({
                        type: '<?=$type?>',
                        layout: 'topCenter',
                        text: '<?= e($message) ?>',
                        timeout: 5000,
                        progressBar: false,
                        closeWith: ['click', 'button']
                    }).show()
                <?php endforeach;
            }
            ?>
        </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      • 2018-02-28
      • 1970-01-01
      • 2020-12-01
      • 2021-12-12
      • 1970-01-01
      • 2018-04-22
      相关资源
      最近更新 更多