狼群ps-天空大师扩展插件_扩展OctoberCMS-构建软删除插件

本文展示了如何扩展OctoberCMS的Rainlab博客插件以实现软删除功能。通过创建新插件,修改数据库架构,扩展列表显示,添加过滤器以及利用Eloquent事件,实现了在删除帖子时仅更新标记而不会真正删除记录的功能。
摘要由CSDN通过智能技术生成

狼群ps-天空大师扩展插件

Developers usually stick with a new CMS for its simplicity and extensibility. OctoberCMS presents itself as a back to basics CMS, and provides an enjoyable experience for both developers and users. In this article, I’m going to demonstrate some aspects of the CMS that make it extensible, and we’ll also try a simple plugin to extend another plugin functionality.

开发人员通常会坚持使用新的CMS,因为它具有简单性和可扩展性。 OctoberCMS表示自己是对CMS的回归,并为开发人员和用户提供了愉快的体验。 在本文中,我将演示使CMS具有可扩展性的某些方面,我们还将尝试使用一个简单的插件来扩展另一个插件功能。

OctoberCMS LOGO

介绍 (Introduction)

Every CMS has a plugin system for extending the platform’s functionality, and we measure the extensibility by how deep into the CMS’ inner workings we can go. However, we’re not only talking about the CMS here, we’re talking about plugins!

每个CMS都有一个用于扩展平台功能的插件系统,我们通过对CMS内部工作的深入程度来衡量可扩展性。 但是,我们不仅在这里谈论CMS,还在谈论插件!

If you build a plugin, you need to make sure that other developers can change bits of your functionality. For example, we have a blog plugin and the user can publish a post by selecting it on a list. It would be a good idea to fire an event saying that a new post has been published, and another developer may hook into this event and notify subscribed users via email about this!

如果您构建插件,则需要确保其他开发人员可以更改您的功能。 例如,我们有一个博客插件,用户可以通过在列表中选择帖子来发布帖子。 引发一个事件,说已经发布了一个新帖子,这是一个好主意,另一个开发人员可能会加入该事件并通过电子邮件通知订阅的用户!

class Posts extends Controller
{
    public function index_onPublish()
    {
        if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {

            foreach ($checkedIds as $postId) {
                if ((!$post = Post::find($postId)) || !$post->canEdit($this->user))
                    continue;

                $post->publish();
                Event::fire('rainlab.blog.posts.published', [$post]);
            }

            Flash::success('Successfully published those posts.');
        }

        return $this->listRefresh();
    }
}

The other developer can listen for this event to do something with the published post.

其他开发人员可以侦听此事件以对已发布的帖子执行某些操作。

Event::listen('rainlab.blog.posts.published', function($post) {
    User::subscribedTo($post).each(function($user) use($post) {
        Mail::send('emails.notifications.post-published', ['user' => $user, 'post' => $post], function($message) use($user, $post) {
            $message->from('us@example.com', 'New post by ' 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值