xml - magento 2 如何向 di.xml 上的数组添加新值

标签 xml magento-2.0

你好!
有常规 app/etc/di.xml 的一部分,我需要在 reader 数组中添加附加值。

 <virtualType name="bodyRenderPool" type="Magento\Framework\View\Layout\ReaderPool">
        <arguments>
            <argument name="readers" xsi:type="array">
                <item name="container" xsi:type="string">Magento\Framework\View\Layout\Reader\Container</item>
                <item name="block" xsi:type="string">Magento\Framework\View\Layout\Reader\Block</item>
                <item name="move" xsi:type="string">Magento\Framework\View\Layout\Reader\Move</item>
                <item name="uiComponent" xsi:type="string">Magento\Framework\View\Layout\Reader\UiComponent</item>
            </argument>
        </arguments>
    </virtualType>

如果是我自己模块的di.xml中标明的

<virtualType name="bodyRenderPool" type="Magento\Framework\View\Layout\ReaderPool">
    <arguments>
        <argument name="readers" xsi:type="array">
            <item name="customEl" xsi:type="string">Company\MyModule\View\Layout\Reader\Customel</item>
        </argument>
    </arguments>
</virtualType>

该数组已被覆盖。
如何在 reader 数组中添加一个元素?

最佳答案

您的错误可能在 di.xml 的范围内

它可以有三个范围:

etc/di.xml
etc/frontend/di.xml
etc/adminhtml/di.xml

确保您要覆盖的 di.xml 和 di.xml 具有相同的范围。

在您的情况下,您可能会将 di.xml 放入前端范围,而 magento 更喜欢使用合并它的 di.xml。

关于xml - magento 2 如何向 di.xml 上的数组添加新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34635615/

相关文章:

java.lang.IllegalArgumentException : InputStream to parse is null

c++ - 找不到 OpenCV haarcascade_frontalface_alt.xml

magento-2.0 - Magento 2.0 未知模块 : error when enabling custom module from command line

magento - "setup"命名空间 : Magento 2 中没有定义命令

php - 共享服务器上的 Magento 2.0.2 安装 - 卡在 66%

css - codeception 无法点击 xpath,因为它无法定位 CSS 或 Xpath

java - 编写 XML 元素时设置属性的顺序

java - 如何使用 Smack 库发送自定义 XML 数据?

javascript - magento2中的媒体存储浏览器字段