magento helper

模块结构

Java代码   收藏代码
  1. app/code/local/App/Shopping/etc    
  2. app/code/local/App/Shopping/Helper    

etc/config.xml中启用helper

Java代码   收藏代码
  1. </models>  
  2. <helpers>  
  3.     <shopping>  
  4.         <class>App_Shopping_Helper</class>  
  5.     </shopping>  
  6. </helpers>    

添加etc/system.xml,然后在管理后台添加配置数据, 系统->配置

Java代码   收藏代码
  1. <?xml version="1.0"?>  
  2. <config>  
  3.     <tabs>  
  4.         <shopping translate="label" module="shopping">  
  5.             <label>The virtualcurrency</label>  
  6.             <sort_order>300</sort_order>  
  7.         </shopping>  
  8.     </tabs>  
  9.     <sections>  
  10.           <shopping translate="label" module="shopping"> <!-- section shopping 权限标签-->  
  11.             <label>显示名称</label>  
  12.             <tab>shopping</tab>  
  13.             <sort_order>100</sort_order>  
  14.             <show_in_default>1</show_in_default>  
  15.             <show_in_website>1</show_in_website>  
  16.             <show_in_store>1</show_in_store>  
  17.             <groups>  
  18.                 <settings translate="label">  
  19.                     <label>基本</label>  
  20.                     <frontend_type>text</frontend_type>  
  21.                     <sort_order>0</sort_order>  
  22.                     <show_in_default>1</show_in_default>  
  23.                     <show_in_website>1</show_in_website>  
  24.                     <show_in_store>1</show_in_store>  
  25.                     <fields>  
  26.                         <name translate="label">  
  27.                             <label>Settings</label>  
  28.                         </name>  
  29.                         <renmingbi_duidian translate="label">  
  30.                             <label>1人民币可以冲值多少</label>  
  31.                             <frontend_type>text</frontend_type>  
  32.                             <sort_order>0</sort_order>  
  33.                             <show_in_default>1</show_in_default>  
  34.                             <show_in_website>1</show_in_website>  
  35.                             <show_in_store>1</show_in_store>  
  36.                         </renmingbi_duidian>  
  37.                     </fields>  
  38.                 </settings>  
  39.             </groups>  
  40.         </shopping>  
  41.     </sections>  
  42. </config>  

config.xml中配置权限,否则后台菜单404

Java代码   收藏代码
  1. </frontend>  
  2. <adminhtml>  
  3.     <acl>  
  4.         <resources>  
  5.             <admin>  
  6.                 <children>  
  7.                     <system>  
  8.                         <children>  
  9.                             <config>  
  10.                                 <children>  
  11.                                     <shopping>  
  12.                                         <title>shoping权限</title>  
  13.                                     </shopping>  
  14.                                 </children>  
  15.                             </config>  
  16.                         </children>  
  17.                     </system>  
  18.                 </children>  
  19.             </admin>  
  20.         </resources>  
  21.     </acl>  
  22. </adminhtml>  

上面配置好后台就可以看到界面。 helper下的data.php

Java代码   收藏代码
  1. <?php  
  2. class App_Shopping_Helper_Data extends Mage_Core_Helper_Abstract  
  3. {   //数据存到core_config_data表中了  
  4.     const XML_PATH_RECHARGE_MONEY = 'shopping/settings/renmingbi_duidian';  
  5.     public function getCurrencyToMoney($store = null)  
  6.     {  
  7.         return Mage::getStoreConfig(self::XML_PATH_RECHARGE_MONEY, $store);  
  8.     }  
  9. }  

help怎么调用

Mage::helper('shopping/data')->getCurrencyToMoney();//data为默认,可以不写

Mage::helper('shopping')->getCurrencyToMoney();

App_Shopping_Helper_Data::XML_PATH_RECHARGE_MONEY

 

Magento 后台配置中实现日期选择

Java代码   收藏代码
  1. <?php  
  2.   
  3. class Glamour_Glscore_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field {  
  4.     protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {  
  5.         $date = new Varien_Data_Form_Element_Date;  
  6.         $format = 'yyyy-MM-dd HH:mm:ss';  
  7.   
  8.         $data = array(  
  9.             'name' => $element->getName(),  
  10.             'html_id' => $element->getId(),  
  11.             'image' => $this->getSkinUrl('images/grid-cal.gif'),  
  12.             'time' => true  
  13.         );  
  14.         $date->setData($data);  
  15.         $date->setValue($element->getValue(), $format);  
  16.         $date->setFormat('yyyy-MM-dd HH:mm:ss');  
  17.         $date->setForm($element->getForm());  
  18.   
  19.         return $date->getElementHtml();  
  20.     }  
  21. }  

在system.xml中使用新的Field类

Java代码   收藏代码
  1. <start_date translate="label">  
  2.     <label>有效期至</label>  
  3.     <frontend_type>text</frontend_type>  
  4.     <frontend_model>Glamour_Glscore_Block_Adminhtml_System_Config_Date</frontend_model>  
  5.     <validate>validate-date</validate>  
  6.     <sort_order>4</sort_order>  
  7.     <show_in_default>1</show_in_default>  
  8.     <show_in_website>1</show_in_website>  
  9.     <show_in_store>1</show_in_store>  
  10. </start_date>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值