浏览文章
文章信息
magento2 xml Notice: Array to string conversion in
13692
Notice: Array to string conversion in原因:
xml数据重复定义,Magento内部在解析xml数据时php解析成为数组,无法解析为字符串
报错例子:
... <label>热门分类</label> <field id="ids" translate="label" type="multiselect" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0"> <label>热门</label> <source_model>Mjd\Hot\Model\Config\Source\Category</source_model> <comment> <![CDATA[<i style='color:red'>提示</i><b style='color:gray'>:按住Ctr键可多选.</b>]]></comment> </field> <label>热门分类</label> <field id="home_hot_ids" translate="label" type="multiselect" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0"> ...你发现<label>热门分类</label>是重复的。
magento在为group元素构造label时将发现是个重复的,将解析成一个数组,虽然两个lable值是一样的但是将变成['lable'=>[1=>‘热门分类’]],而不是['lable'=>‘热门分类’]。lable的值不是字符串,而是数组,magento在使用此数据时发现无法当做字符串使用。所以抛出PHP错误:Notice: Array to string conversion in***
解决:
显然,删除多余的<label>热门分类</label>即可。