2017-04-11 18 views
2

どのようにコントローラを拡張して設定関係filedsを追加するか。関係をどのように拡張するか10月CMS

は、今の私はそれがエラーを誘発するので、私は方法は、私の設定ファイルがすでに存在して消去このような状況でこの

myController::extend(function($controller){ 

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

のように新しいファイルを追加し、新しいものを追加できることを発見し、既に他の関連理由行動は存在しない。

答えて

1

これは、最近議論とhereを文書化されました:

myController::extend(function($controller) { 

    // Implement the relation controller if it doesn't exist already 
    if (!$controller->isClassExtendedWith('Backend.Behaviors.RelationController')) { 
     $controller->implement[] = 'Backend.Behaviors.RelationController'; 
    } 

    // Implement the relationConfig property with our custom config if it doesn't exist already 
    $myConfigPath = '~/plugins/path/languages/config_relation.yaml'; 
    if (!isset($controller->relationConfig)) { 
     $controller->addDynamicProperty('relationConfig', $myConfigPath); 
    } 
    else { 
     // Ensure that we have an instantiated config object to work with 
     $config = $controller->makeConfig($controller->relationConfig); 

     // Instantiate our custom config object to work with 
     $myConfig = $controller->makeConfig($myConfigPath); 

     // Merge the above two 
     $controller->relationConfig = (object) array_merge((array) $config, (array) $myConfig); 
    } 
} 

以下の機能がdevelop支店で、現在newです:

public function mergeConfig($configA, $configB) 
{ 
    $configA = $this->makeConfig($configA); 
    $configB = $this->makeConfig($configB); 
    return (object) array_merge((array) $configA, (array) $configB); 
} 

だから、将来的には、develop分岐はあなたが、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 
    ); 

} 
+0

恐ろしいタンク@meysam –

+0

@ TahaAzzabiドキュメントが更新され、コードが若干変更されました:https://github.com/octobercms/docs/blob/master/services-behaviors.md#detecting-utilized-extensions – Meysam

関連する問題