Magento 2覆盖核心框架

4

我希望覆盖AbstractBlock类,我尝试使用我的自定义模块,但它没有起作用。

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Framework\View\Element\AbstractBlock" type="YourCompany\YourModule\Framework\View\Element\AbstractBlock" />
</config>

AbstractBlock.php

<?php
namespace YourCompany\YourModule\Framework\View\Element;

abstract class AbstractBlock extends \Magento\Framework\View\Element\AbstractBlock {

    /**
     * Retrieve child block HTML
     *
     * @param   string $alias
     * @param   boolean $useCache
     * @return  string
     */
    public function getChildHtml($alias = '', $useCache = true)
    {
        die("here");
    }

}
1个回答

0

你不能在继承层次结构的中间替换一个类。 也就是说,用另一个抽象类替换现有的父(抽象)类。

也许你可以展示一下如何使用原始类(我猜测是在构造函数中),这将有助于给出更好的答案。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接