magento2
依存性注入
サーチ…
引数置換
<!-- <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>
上の例は、オーバーライドコアモデルの構文です。
これを可能にする方法を説明するポイントのリストがここにあります
moduleDir - 拡張ディレクトリ
app/code/custom/extension
と同じように、extension
は、必要なすべての拡張子のフォルダが置かれるディレクトリです。エリア - エリアは
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
for = "Vendor \ Namespace \ Model \ Example"ここでは、目的の機能の機能を無効にするファイルのパスです。
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