magento xml配置详解(2)
Magento 的 config.xml 配置参数详解 Path: app/code/(codepool)/(NameSpace)/(ModuleName)/etc/config.xml当你在Magento中新增一个或更新一个module的时候,需要在此config.xml中对所有的models,blocks,classes等做相应的配置。每一个module都有一个单独的config.xml文
·
Magento 的 config.xml 配置参数详解
Path: app/code/(codepool)/(NameSpace)/(ModuleName)/etc/config.xml
当你在Magento中新增一个或更新一个module的时候,需要在此config.xml中对所有的models,blocks,classes等做相应的配置。每一个module都有一个单独的config.xml文件,但是Magento在加载解析这些config.xml文件的时候整合在一起分析的。所以每个config.xml文件都需要有<(modulename)> 来区别于其他的模块,如果一个模块下的config.xml文件中没有定义<(modulename)> ,该文件中其他的定义将被其他的文件覆盖掉。由此,严格按照Magento要求的书写方式来对相应的Module做配置是非常重要的(例如, <(modulename)_setup>)
XML Structure
<config>
<modules>
<(NameSpace_ModuleName)>...</(NameSpace_ModuleName)>
</modules>
<global>
<models$amp;>amp;$lt;/models>
<resources$amp;>amp;$lt;/resources>
<blocks$amp;>amp;$lt;/blocks>
<helpers$amp;>amp;$lt;/helpers>
<fieldsets$amp;>amp;$lt;/fieldsets>
<template$amp;>amp;$lt;/template>
<events$amp;>amp;$lt;/events>
<eav_attributes$amp;>amp;$lt;/eav_attributes>
<(modulename)$amp;>amp;$lt;!-- custom config variables --$amp;>amp;$lt;/(modulename)>
</global>
<admin>
<attributes$amp;>amp;$lt;/attributes>
<routers$amp;>amp;$lt;/routers>
<fieldsets$amp;>amp;$lt;/fieldsets>
</admin>
<adminhtml>
<events$amp;>amp;$lt;/events>
<global_search$amp;>amp;$lt;/global_search>
<translate$amp;>amp;$lt;/translate>
<layout$amp;>amp;$lt;/layout>
<(modulename)$amp;>amp;$lt;!-- custom config variables --$amp;>amp;$lt;/(modulename)>
</adminhtml>
<install>
<translate$amp;>amp;$lt;/translate>
</install>
<frontend>
<routers$amp;>amp;$lt;/routers>
<events$amp;>amp;$lt;/events>
<translate$amp;>amp;$lt;/translate>
<layout$amp;>amp;$lt;/layout>
</frontend>
<default>
<(modulename)$amp;>amp;$lt;!-- custom config variables --$amp;>amp;$lt;/(modulename)>
</default>
<stores>
<admin$amp;>amp;$lt;/admin>
</stores>
<websites>
<admin$amp;>amp;$lt;/admin>
</websites>
</config>
注意,上面只是一个config.xml配置文件大致的框架,下面将对每一部分进行细致分析.
Elements
Element Description Example
modules 最基本的定义一个模块的名字,版本和是否依赖于其他模块
global
(哈哈!由于global的特性,你可以在其他地方定义一个模块,只要
global下的<moduleName />正确定义该模块就行
admin
adminhtml 对system->configuration下的具体的项进行ACL定义
install Page
frontend 主要定义router
default
stores Adminhtml
websites Adminhtml
每个config.xml可大致分为上面表格中的小模块,下面就每一块进行细分
modules
XML Structure
<modules>
<(NameSpace_ModuleName)>
<active>[true|false]</active>
<codePool>[core|community|local]</codePool>
<depends>
<(AnotherNameSpace_ModuleName) />
</depends>
<version>(version_number)</version>
</(NameSpace_ModuleName>
</modules>
Elements
Element Description
active 该模块是否生效(该element的值可在后台修改)
codePool app/code 的具体路径
depends 是否依赖于其他的模块,如果被依赖的模块不存在,它就不active
version 定义版本,用于更新和安装
通常 active, codePool and depends 一般在 app/etc/modules/(NameSpace)_*.xml 文件中定义,而 version 在相应module下的config.xml 文件中定义.
global
XML Structure
<global>
<models>
<(modulename)>
<class>(ClassName_Prefix)</class>
<resourceModel>(modulename)_(resource_model_type)</resourceModel>
<(modulename)_(resource_model_type)>
<!-- definition -->
</(modulename)_(resource_model_type)>
<rewrite$amp;>amp;$lt;!-- definition --$amp;>amp;$lt;/rewrite>
</(modulename)>
</models>
<resources>
<(modulename)_setup$amp;>amp;$lt;!-- definition --$amp;>amp;$lt;/(modulename)_setup>
<(modulename)_read$amp;>amp;$lt;!-- definition --$amp;>amp;$lt;/(modulename)_read>
<(modulename)_write$amp;>amp;$lt;!-- definition --$amp;>amp;$lt;/(modulename)_write>
</resources>
<blocks>
<(modulename)>
<class>(ClassName_Prefix)</class>
</(modulename)>
</blocks>
<helpers>
<(modulename)>
<class>(ClassName_Prefix)</class>
</(modulename)>
</helpers>
<fieldsets>
<(page_handle )>
<(field_name)> </(field_name)>
</(page_handle )>
</fieldsets>
<template>
<email>
<(email_template_name)
module="(modulename)"
translate="[label][,description]"
>
<!-- definition -->
<(/email_template_name)>
</email>
</template>
<events>
<(event_name)>
<observers$amp;>amp;$lt;!-- observers --$amp;>amp;$lt;/observers>
</(event_name)>
</events>
<eav_attributes$amp;>amp;$lt;!-- definition --$amp;>amp;$lt;/eav_attributes>
<(modulename)$amp;>amp;$lt;!-- custom config variables --$amp;>amp;$lt;/(modulename)>
</global>
Elements
Element Description
models
resources
blocks
helpers
fieldsets
template
events
eav_attributes
(modulename) 自定义的变量(如设置邮件或newletter时非常有用)
admin
XML Structure
<admin>
<attributes>
<(attribute_name) />
<attributes>
<fieldsets$amp;>amp;$lt;!-- definition --$amp;>amp;$lt;/fieldsets>
<routers>
<(modulename)>
<use>[standard|admin|default]</use>
<args>
<module>(NameSpace_ModuleName)</module>
<frontName>(frontname)</frontName>
</args>
</(modulename)>
<!-- or -->
<(modulename)>
<args>
<modules>
<(NameSpace_ModuleName)
before="(AnotherNameSpace_ModuleName)"
>
(New_ClassName)
<(NameSpace_ModuleName)
</args>
</(modulename)>
</routers>
</admin>
Elements
Element Description
attributes
fieldsets
routers
adminhtml
XML Structure
<adminhtml>
<events>
<(event_name)>
<observers$amp;>amp;$lt;!-- observers --$amp;>amp;$lt;/observers>
</(event_name)>
</events>
<global_search>
<products>
<class>(modulename)/search_catalog</class>
<acl>catalog</acl>
</products>
<customers>
<class>adminhtml/search_customer</class>
<acl>customer</acl>
</customers>
<sales>
<class>adminhtml/search_order</class>
<acl>sales</acl>
</sales>
</global_search>
<translate>
<modules>
<(NameSpace_ModuleName)>
<files>
<default>(name_of_translation_file.csv)</default>
</files>
</(NameSpace_ModuleName)>
</modules>
</translate>
<layout>
<updates>
<(modulename)>
<file>(name_of_layout_file.xml)</file>
</(modulename)>
</updates>
</layout>
<(modulename)$amp;>amp;$lt;!-- custom config variables --$amp;>amp;$lt;/(modulename)>
</adminhtml>
Elements
Element Description
events
global_search
translate
layout
(modulename) 自定义变量
install
XML Structure
frontend
XML Structure
<frontend>
<secure_url>
<(page_handle)>/relative/url</page_handle>
</secure_url>
<events>
<(event_name)>
<observers$amp;>amp;$lt;!-- observers --$amp;>amp;$lt;/observers>
</(event_name)>
</events>
<routers>
<(modulename)>
<use>[standard|admin|default]</use>
<args>
<module>(NameSpace_ModuleName)</module>
<frontName>(frontname)</frontName>
</args>
</(modulename)>
</routers>
<translate>
<modules>
<(NameSpace_ModuleName)>
<files>
<default>(name_of_translation_file.csv)</default>
</files>
</(NameSpace_ModuleName)>
</modules>
</translate>
<layout>
<updates>
<(modulename)>
<file>(name_of_layout_file.xml)</
</(modulename)>
</updates>
</layout>
</frontend>
Elements
Element Description
secure_url
events
routers
translate
layout
default
XML Structure
stores
XML Structure
websites
XML Structure
更多推荐
所有评论(0)