【问题标题】:How to change successful flash message in Rainlab Blog Plugin while creating a post?创建帖子时如何在 Rainlab 博客插件中更改成功的 Flash 消息?
【发布时间】:2017-08-13 18:07:47
【问题描述】:

我在我的网站上使用十月 CMS 和 Rainlab 博客插件。每当我在后端的博客部分创建帖子时,我都会看到一条显示“博客帖子已创建”的消息。因为它在我创建帖子后立即出现,我需要知道在哪里可以找到运行此 Flash 消息的方法。在插件文件夹中搜索没有给出任何结果,也许我遗漏了什么?

【问题讨论】:

    标签: php laravel octobercms flash-message


    【解决方案1】:

    它在 FormController 行为中定义,它基于模型名称和执行的操作,您可以在模型中的 apropiated afterX 方法上覆盖它。

    public function afterSave()
    {
        Flash::purge();//clean the default messages
        Flash::success('Your custom message');
    }
    

    记得在文件顶部导入 Flash Facade。

    use Flash;

    另外我建议使用语言文件来保持干净

    public function afterSave()
    {
        Flash::purge();
        Flash::success('namespace.plugin.lang.code');
    }
    

    如果您不想触碰任何 Rainlab 博客文件,您可以从您的另一个插件绑定中执行此操作,在您的 Plugin.php 定义中监听启动事件所需的事件

    public function boot()
    {
        RainLabModelPost::extend(function ($model) {
            $model->bindEventOnce('model.afterSave', function () use ($model) {
                Flash::purge();
                Flash::success('namespace.plugin.lang.code');
            });
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-24
      • 2018-06-17
      • 2013-03-07
      • 1970-01-01
      • 2018-04-11
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多