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>
위의 예는 override 핵심 모델의 구문입니다.
가능한 방법을 설명하는 요점 목록이 있습니다.
moduleDir - 확장 디렉토리
app/code/custom/extension
과 같이 여기에extension
은 필요한 모든 확장 폴더가 배치 될 디렉토리입니다.영역 - 영역은
frontend
또는adminhtml
프론트 엔드 - 확장 기능이 frontend의 기능을
di.xml
폴더에서 사용하는 경우adminhtml - 확장 프로그램이 di.xml보다
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