在phalcon中使用自定义事件

2,627次阅读

共计 550 个字符,预计需要花费 2 分钟才能阅读完成。

lass Comment
{const NAME = 'comment';

    const NAME_PUBLISH = 'comment:publish';
}
class CommentListener extends Plugin
{public function publish(Event $event)
    {}}

/**
 * Class CommentController
 * @package app\controllers
 */
class CommentController extends BaseController
{public function initialize()
    {// 监听事件 
        $this->eventsManager->attach(Comment::NAME, new CommentListener());
    }

    /**
     * 发表一条评价
     * @return string
     */
    public function publishAction()
    {$post = $this->request->getPost();
        if ($this->db->insertAsDict('comments', $post) {$this->eventsManager->fire(Comment::NAME_PUBLISH, null);// 扫行事件 
            return 0;
        }
        return 500;
    }
}

正文完
 
Blood.Cold
版权声明:本站原创文章,由 Blood.Cold 2019-06-03发表,共计550字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。