如何在创建 post 时更改 Rainlab 博客插件中的成功闪现消息?
How to change successful flash message in Rainlab Blog Plugin while creating a post?
我在我的网站上使用 October CMS 和 Rainlab 博客插件。每当我在后端的博客部分创建 post 时,我都会看到一条闪现消息,上面写着 "Blog post created." 因为它在我创建 post 后立即出现,我需要知道在哪里可以找到运行此 Flash 消息的方法。在插件文件夹中搜索没有给出任何结果,也许我遗漏了什么?
它是在 FormController
行为中定义的,它基于模型名称和执行的操作,您可以在模型中的适当 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');
});
});
}
我在我的网站上使用 October CMS 和 Rainlab 博客插件。每当我在后端的博客部分创建 post 时,我都会看到一条闪现消息,上面写着 "Blog post created." 因为它在我创建 post 后立即出现,我需要知道在哪里可以找到运行此 Flash 消息的方法。在插件文件夹中搜索没有给出任何结果,也许我遗漏了什么?
它是在 FormController
行为中定义的,它基于模型名称和执行的操作,您可以在模型中的适当 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');
});
});
}