magento2 XML配置说明

di.xml 指定或重写Proxy

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- for = 受影响的原始类或接口 -->
    <!-- type = 所依赖的Proxy -->
   <preference for="Magento\Contact\Controller\Index\Post" type="Infinity\Contact\Controller\Index\Post" />
</config>

ps: 重写 block 时如涉及读取组件模板,可能也需要把 phtml 复制到当前 module 中

di.xml 指定或重写某个类中构造函数入参所依赖Proxy

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- name = 受影响的原始类 -->
    <type name="[vendor]\[Module]\Xxx">
        <arguments>
            <!-- name = __construct函数的参数名 -->
            <!-- text() = 指定所依赖的Proxy -->
            <argument name="arg1" xsi:type="object">[vendor]\[Module]\Xxxxx\Proxy</argument>
        </arguments>
    </type>
</config>

di.xml 声明plugin,用于修改目标类若干个method的入参或者返回结果

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- name = 需要执行插件的类。包含空间名 -->
    <type name="Magento\Customer\Model\Resource\Visitor">
        <!-- name = plugin name,全局唯一 -->
        <!-- sortOrder = 运行顺序 -->
        <!-- disabled = 是否关闭plugin -->
        <plugin name="catalogLog"
            type="Magento\Catalog\Model\Plugin\Log"
            sortOrder="1"
            disabled="true" />
    </type>
</config>

http://devdocs.magento.com/gu...

layout

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <!-- 通过layout可以修改title -->
        <referenceBlock name="page.main.title">
            <action method="setPageTitle">
                <argument translate="true" name="title" xsi:type="string">Page Title</argument>
            </action>
        </referenceBlock>
        <!-- container将声明容器,block必须放在container内 -->
        <container name="div.sidebar.additional" htmlTag="div" htmlClass="sidebar sidebar-additional" after="div.sidebar.main">
            <container name="sidebar.additional" as="sidebar_additional" label="Sidebar Additional"/>
        </container>
        <!-- referenceContainer对已存在容器进行改造 -->
        <referenceContainer name="sidebar.additional">
            <!-- block将声明区块 -->
            <block class="Magento\Framework\View\Element\Template" name="catalog.compare.sidebar"
                   template="Magento_Catalog::product/compare/sidebar.phtml">
                <!-- action将直接调用block class中的方法 -->
                <action method="setText">
                    <argument name="text" translate="true" xsi:type="string">Text</argument>
                </action>
                <!-- arguments是block class的属性列表,从于从XML传递参数到class -->
                <arguments>
                    <!-- cache生命周期 -->
                    <argument name="cache_lifetime" xsi:type="number">84600</argument>
                </arguments>
            </block>
            <!-- referenceBlock对已存在block进行改造,例如删除它,或修改arguments -->
            <referenceBlock name="catalog.compare.sidebar" remove="true" />
            <!-- move移动元素 -->
            <move element="name.of.an.element" destination="name.of.destination.element" as="new_alias" after="name.of.element.after" before="name.of.element.before"/>
        </referenceContainer>
    </body>
</page>

webapi.xml 声明webapi

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
    <!-- url = 外部访问的URL -->
    <!-- method = 请求方式 (GET,POST,PUT,DELETE) -->
    <route url="/V1/customerGroups/:id" method="GET">
        <service class="Magento\Customer\Api\GroupRepositoryInterface" method="getById"/>
        <!-- ACL资源,用于控制API的访问权 -->
        <resources>
            <resource ref="Magento_Customer::group"/>
        </resources>
    </route>
</routes>

events.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch">
        <observer name="infinity_autocoupon_controller_action_predispatch" instance="Infinity\AutoCoupon\Observer\Predispatch" />
    </event>
</config>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇