Magento2开发教程-XML配置说明

7天成为Magento系统架构师,现在开始学习Magento全栈开发!

《Magento2.X企业级开发实战》

di.xml 指定或重写Proxy

config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    
    
   preference for="MagentoContactControllerIndexPost" type="InfinityContactControllerIndexPost" />
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">
    
    type name="[Vendor][Module]Xxx">
        arguments>
            
            
            argument name="arg1" xsi:type="object">[Vendor][Module]XxxxxProxyargument>
        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">
    
    type name="MagentoCustomerModelResourceVisitor">
        
        
        
        plugin name="catalogLog"
            type="MagentoCatalogModelPluginLog"
            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>
        
        referenceBlock name="page.main.title">
            action method="setPageTitle">
                argument translate="true" name="title" xsi:type="string">Page Titleargument>
            action>
        referenceBlock>
        
        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 name="sidebar.additional">
            
            block class="MagentoFrameworkViewElementTemplate" name="catalog.compare.sidebar"
                   template="Magento_Catalog::product/compare/sidebar.phtml">
                
                action method="setText">
                    argument name="text" translate="true" xsi:type="string">Textargument>
                action>
                
                arguments>
                    
                    argument name="cache_lifetime" xsi:type="number">84600argument>
                arguments>
            block>
            
            referenceBlock name="catalog.compare.sidebar" remove="true" />
            
            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">
    
    
    route url="/V1/customerGroups/:id" method="GET">
        service class="MagentoCustomerApiGroupRepositoryInterface" method="getById"/>
        
        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="InfinityAutoCouponObserverPredispatch" />
    event>
config>

文章来源于互联网:Magento2开发教程NO14-XML配置说明

如无特殊说明或标注,任何个人或组织,复制、转载、采集本站内容请注明:
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。