OctoberCMS:如何通过添加或编辑 RelationController 来扩展控制器?

OctoberCMS: How to extend a controller by adding or editing RelationController?

我们如何通过将 Backend.Behaviors.RelationController 添加到其控制器之一来扩展插件?我需要扩展 User Plugin and add a belongsToMany relationship to its User model. I also want to extend its Users controller to implement the Backend.Behaviors.RelationController behavior. I know that form fields can be extended using extendFormFields and list columns can be extended using extendListColumns. But what about extending a plugin by adding or editing the RelationController 行为吗?

阅读 Behavior documentation,特别是因为它与扩展 类 以实现新行为有关。

本质上,您需要扩展用户控制器以实现 RelationController 行为并配置该行为。完成该操作的代码示例如下:

UsersController::extend(function($controller) {
    $controller->implement[] = ['Backend.Behaviors.RelationController'];
    $controller->relationConfig = '$/myvendor/myplugin/controllers/users/config_relation.yaml'
});