你好!
有常规 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/