示例路径如下:D:\htdocs\magento_a\app\code\local\Exercise\Avatar
第一步:建module的配置文件 D:\htdocs\magento_a\app\etc\modules\Exercise_Avatar.xml
<?xml version="1.0"?>
<config>
<modules>
<Exercise_Avatar>
<active>true</active>
<codePool>local</codePool>
</Exercise_Avatar>
</modules>
</config>
第二步:D:\htdocs\magento_a\app\code\local\Exercise\Avatar\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Exercise_Avatar>
<version>0.1.0</version>
</Exercise_Avatar>
</modules>
<frontend>
<routers><!--创建前台访问的路由-->
<avatar>
<use>standard</use>
<args>
<module>Exercise_Avatar</module><!--注意此处的值应该和当前创建的module一致-->
<frontName>avatar</frontName>
</args>
</avatar>
</routers>
</frontend>
<global>
<helpers>
<avatar>
<class>Exercise_Avatar_Helper</class>
</avatar>
</helpers>
</global>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<exercise><!--注意此处的mode name,与下面的system.xml的config->sections->exercise对应-->
<title>avatar</title><!--此节点的值可随意修改-->
</exercise>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
第三步:system.xml
<config>
<tabs>
<avatar translate="label" module="avatar">
<label>Avatar</label>
<sort_order>100</sort_order>
</avatar>
</tabs>
<sections>
<exercise translate="label" module="avatar"><!-- 这里的节点名和上面config.xml中的节点对应,它们需要保持一致-->
<label>Set customer avatar profile</label>
<tab>avatar</tab>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<avatar translate="label">
<label>set max size of picture</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<avatar_width translate="label">
<label>width</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>px</comment>
</avatar_width>
<avatar_height translate="label">
<label>height</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>px</comment>
</avatar_height>
</fields>
</avatar>
<enable translate="label">
<label>show avatar</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<avatar_enable translate="label">
<label>enable avatar</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>show avatar in frontend</comment>
</avatar_enable>
</fields>
</enable>
</groups>
</exercise>
</sections>
</config>
第四步: D:\htdocs\magento_a\app\code\local\Exercise\Avatar\Helper\Data.php
<?php
class Exercise_Avatar_Helper_Data extends Mage_Core_Helper_Abstract
{
}
此时可刷新后台,新设定的配置将会显示在system->configuration,general的下面.点击进去可以看到所设置的两组配置项.结果如下图.
第五步:
取配置所设定的值
D:\htdocs\magento_a\app\code\local\Exercise\Avatar\controllers\IndexController.php
<?php
class Exercise_Avatar_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
echo Mage::getStoreConfig('exercise/avatar/avatar_width');//注意此处参数与节点对应
echo Mage::getStoreConfig('exercise/avatar/avatar_height');
echo Mage::getStoreConfig('exercise/enable/avatar_enable');
}
}
注意:如果点''Set customer avatar profile'',右边显示404错误,重新登录后可解决. 如有其它问题,欢迎留言.
相关源代码可从下面链接下载:http://download.youkuaiyun.com/detail/emily_init/4600477
关于xml更详细的解释可见:http://www.magentocommerce.com/wiki/5_-_modules_and_development/admin/xml_structure_for_admin_configurations
