【问题标题】:OctoberCMS: How to extend a controller by adding or editing RelationController?OctoberCMS:如何通过添加或编辑 RelationController 来扩展控制器?
【发布时间】:2017-04-25 15:31:10
【问题描述】:
我们如何通过将Backend.Behaviors.RelationController 添加到其控制器之一来扩展插件?我需要扩展User Plugin 并将belongsToMany 关系添加到其User 模型。我还想扩展它的Users 控制器来实现Backend.Behaviors.RelationController 行为。我知道可以使用extendFormFields 扩展表单字段,并且可以使用extendListColumns 扩展列表列。但是如何通过添加或编辑 RelationController 行为来扩展插件呢?
【问题讨论】:
标签:
php
laravel
octobercms
octobercms-plugins
【解决方案1】:
阅读Behavior documentation,特别是它与扩展类以实现新行为有关。
基本上,您需要扩展用户控制器以实现RelationController 行为并配置该行为。下面是一个代码示例:
UsersController::extend(function($controller) {
$controller->implement[] = ['Backend.Behaviors.RelationController'];
$controller->relationConfig = '$/myvendor/myplugin/controllers/users/config_relation.yaml'
});