サーチ…


引数置換

<!-- <moduleDir>/etc/<area>/di.xml -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- ... -->
    <type name="Vendor\Namespace\Model\SomeClass">
        <arguments>
            <argument name="object" xsi:type="object">Vendor\Namespace\Model\SomeOtherClass</argument>
        </arguments>
    </type>
</config>

クラス設定

<!-- <moduleDir>/etc/<area>/di.xml -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- ... -->
    <preference
        for="Vendor\Namespace\Model\Example"
        type="Vendor\Namespace\Model\AnotherExample" />
<!-- ... -->
</config>

上の例は、オーバーライドコアモデルの構文です。

これを可能にする方法を説明するポイントのリストがここにあります

  1. moduleDir - 拡張ディレクトリapp/code/custom/extensionと同じように、 extensionは、必要なすべての拡張子のフォルダが置かれるディレクトリです。

  2. エリア - エリアはfrontendまたはadminhtmlなります

    • フロントエンド -より拡張はフロントエンドの機能を使用する場合di.xml意志は、このフォルダにに行きます

    • adminhtml -拡張子はadminpanelの機能を使用する場合よりも、 di.xml意志がこのフォルダ内に行きます

    • app/code/custom/extension/etc/frontend/di.xmlまたはapp/code/custom/extension/etc/adminhtml/di.xml

    • より機能性の両方を使用したい場合はdi.xmlファイルの意志ダイレクトで行かないetcに置くフォルダ必要frontendまたはadminhtmlフォルダが。 Like - app/code/custom/extension/etc/di.xml

  3. for = "Vendor \ Namespace \ Model \ Example"ここでは、目的の機能の機能を無効にするファイルのパスです。

  4. type = "Vendor \ Namespace \ Model \ AnotherExample"ここでは、 step - 3オーバーライドする関数を提供するファイルのパスです

コンストラクタインジェクション

/**
 * @var \Vendor\Module\Helper\Data
 */
protected $customHelper;

/**
 * Constructor call
 * @param \Vendor\Module\Helper\Data $customHelper
 */
public function __construct(
    \Vendor\Module\Helper\Data $customHelper
)
{
    $this->customHelper = $customHelper;
    parent::__construct();
}


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow