magento自定义后台配置
2012-09-26 18:07
253 查看
示例路径如下: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.csdn.net/detail/emily_init/4600477
关于xml更详细的解释可见:http://www.magentocommerce.com/wiki/5_-_modules_and_development/admin/xml_structure_for_admin_configurations
第一步:建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.csdn.net/detail/emily_init/4600477
关于xml更详细的解释可见:http://www.magentocommerce.com/wiki/5_-_modules_and_development/admin/xml_structure_for_admin_configurations
![](http://img.my.csdn.net/uploads/201209/26/1348654513_7308.jpg)
相关文章推荐
- Magento如何在XML配置文件中自定义页面title?
- magento中模块开发实例,前后台开发,前台表单提交,页面配置显示
- 配置magento后台翻译
- 深入理解Magento - 第七章 – 自定义Magento系统配置
- magento安装新插件后后台配置空白解决办法
- Magento入门基础 - 在magento后台增加一个自定义订单状态
- 自定义Magento系统配置
- magento 后台取产品自定义的select(下拉菜单)字段
- 第七章 – 自定义Magento系统配置1
- 第七章 – 自定义Magento系统配置2
- Magento 后台自定义导出订单
- magento2 配置自定义定时任务(cron )和计划组(cron group)教程
- magento 开发 -- 深入理解Magento第七章 – 自定义Magento系统配置
- Magento1.4中后台xml配置文件与1.3不同之处
- magento - 后台提示服务器配置错误导致包含敏感信息的配置文件可浏览
- 自定义Magento系统配置
- 第七章 – 自定义Magento系统配置
- 自定义一个带箭头旋转的圆圈 , 配置服务器后台
- 如何在magento后台增加一个自定义订单状态
- 后台邮箱配置SMTP函数,如何把发件人设置为自定义昵称