Octobercms 如何在CMS中扩展关系配置

Octobercms 如何在CMS中扩展关系配置,octobercms,Octobercms,如何扩展控制器以添加配置关系文件 现在我发现我可以像这样添加一个新文件 myController::extend(function($controller){ $controller->relationConfig = '~/plugins/path/languages/config_relation.yaml'; }); 在这种情况下,方法“擦除我的配置文件”已经存在,并添加一个新的配置文件,从而触发错误,因为其他配置文件已经不存在。最近讨论并记录了这一点: 以下

如何扩展控制器以添加配置关系文件

现在我发现我可以像这样添加一个新文件

 myController::extend(function($controller){

$controller->relationConfig = '~/plugins/path/languages/config_relation.yaml';
        }); 

在这种情况下,方法“擦除我的配置文件”已经存在,并添加一个新的配置文件,从而触发错误,因为其他配置文件已经不存在。

最近讨论并记录了这一点:

以下功能目前在
develope
分支中:

public function mergeConfig($configA, $configB)
{
    $configA = $this->makeConfig($configA);
    $configB = $this->makeConfig($configB);
    return (object) array_merge((array) $configA, (array) $configB);
}
因此,在将来,
develope
分支合并到
master
之后,您将能够使用以下代码合并配置:

UsersController::extend(function($controller) {

    // Implement behavior if not already implemented
    if (!$controller->isClassExtendedWith('Backend.Behaviors.RelationController')) {
        $controller->implement[] = 'Backend.Behaviors.RelationController';
    }

    // Define property if not already defined
    if (!isset($controller->relationConfig)) {
        $controller->addDynamicProperty('relationConfig');
    }

    // Splice in configuration safely
    $myConfigPath = '$/myvendor/myplugin/controllers/users/config_relation.yaml';

    $controller->relationConfig = $controller->mergeConfig(
        $controller->relationConfig,
        $myConfigPath
    );

}

可怕的坦克@meysam@TahaAzzabi文档已更新,代码略有更改:
UsersController::extend(function($controller) {

    // Implement behavior if not already implemented
    if (!$controller->isClassExtendedWith('Backend.Behaviors.RelationController')) {
        $controller->implement[] = 'Backend.Behaviors.RelationController';
    }

    // Define property if not already defined
    if (!isset($controller->relationConfig)) {
        $controller->addDynamicProperty('relationConfig');
    }

    // Splice in configuration safely
    $myConfigPath = '$/myvendor/myplugin/controllers/users/config_relation.yaml';

    $controller->relationConfig = $controller->mergeConfig(
        $controller->relationConfig,
        $myConfigPath
    );

}