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></models>
??????? <resources></resources>
??????? <blocks></blocks>
??????? <helpers></helpers>
??????? <fieldsets></fieldsets>
??????? <template></template>
??????? <events></events>
??????? <eav_attributes></eav_attributes>
??????? <(modulename)><!-- custom config variables --></(modulename)>
??? </global>
??? <admin>
??????? <attributes></attributes>
??????? <routers></routers>
??????? <fieldsets></fieldsets>
??? </admin>
??? <adminhtml>
??????? <events></events>
??????? <global_search></global_search>
??????? <translate></translate>
??????? <layout></layout>
??????? <(modulename)><!-- custom config variables --></(modulename)>
??? </adminhtml>
??? <install>
??????? <translate></translate>
??? </install>
??? <frontend>
??????? <routers></routers>
??????? <events></events>
??????? <translate></translate>
??????? <layout></layout>
??? </frontend>
??? <default>
??????? <(modulename)><!-- custom config variables --></(modulename)>
??? </default>
??? <stores>
??????? <admin></admin>
??? </stores>
??? <websites>
??????? <admin></admin>
??? </websites>
</config>
注意,上面只是一个config.xml配置文件大致的框架,下面将对每一部分进行细致分析.
Elements
ElementDescriptionExample
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
ElementDescription
active该模块是否生效(该element的值可在后台修改)
codePoolapp/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><!-- definition --></rewrite>
??????????? </(modulename)>
??????? </models>
??????? <resources>
??????????? <(modulename)_setup><!-- definition --></(modulename)_setup>
??????????? <(modulename)_read><!-- definition --></(modulename)_read>
??????????? <(modulename)_write><!-- definition --></(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><!-- observers --></observers>
??????????? </(event_name)>
??????? </events>
??????? <eav_attributes><!-- definition --></eav_attributes>
??????? <(modulename)><!-- custom config variables --></(modulename)>
??? </global>
Elements
ElementDescription
models
resources
blocks
helpers
fieldsets
template
events
eav_attributes
(modulename)自定义的变量(如设置邮件或newletter时非常有用)
admin
XML Structure
??? <admin>
??????? <attributes>
??????????? <(attribute_name) />
??????? <attributes>
??????? <fieldsets><!-- definition --></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
ElementDescription
attributes
fieldsets
routers
adminhtml
XML Structure
??? <adminhtml>
??????? <events>
??????????? <(event_name)>
??????????????? <observers><!-- observers --></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)><!-- custom config variables --></(modulename)>
??? </adminhtml>
Elements
ElementDescription
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><!-- observers --></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
ElementDescription
secure_url
events
routers
translate
layout
default
XML Structure
stores
XML Structure
websites
XML Structure
?