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>  
相关文章
|
数据库连接 PHP
使用composer安装laravel-admin及其过程中遇到的坑
使用composer安装laravel-admin及其过程中遇到的坑
215 0
|
中间件 数据库 Python
【Django知识补充 - 1】:admin站点和rest_framework实现文件的上传和下载
【Django知识补充 - 1】:admin站点和rest_framework实现文件的上传和下载
265 0
【Django知识补充 - 1】:admin站点和rest_framework实现文件的上传和下载
|
PHP
【laravel报错】You don‘t have permission to access /laravel/public/index.php on this server.
【laravel报错】You don‘t have permission to access /laravel/public/index.php on this server.
98 0
【laravel报错】You don‘t have permission to access /laravel/public/index.php on this server.
【谷歌】安装Xdebug helper debug插件
【谷歌】安装Xdebug helper debug插件
405 0
【谷歌】安装Xdebug helper debug插件
|
PHP Apache Windows
wordpress 下载主题模板、更新报错 No working transports found解决办法
出错原因是PHP没有开启curl. windows下开启方法如下 1. 将php.ini中的;extension=php_curl.dll前的分号去掉, 2. 将php中libeay32.
|
Java 数据格式 XML
|
JavaScript 程序员 PHP
【Yii2】Yii2执行完composer install 出现 vendor/bower/jquery/dist 找不到的解决方案
问题 在我们的项目中,vender的部分不会放在文件仓库内,而是被忽略掉。 删除项目内的“vender“`文件夹 在项目根目录执行composer install 访问项目,出现报错 The file or directory to be publi...
1516 0