Magento后台配置中实现日期选择,首先,创建一个新的Form Field 类:
<?php
class Glamour_Glscore_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$date = new Varien_Data_Form_Element_Date;
$format = 'yyyy-MM-dd HH:mm:ss';
$data = array(
'name' => $element->getName(),
'html_id' => $element->getId(),
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'time' => true
);
$date->setData($data);
$date->setValue($element->getValue(), $format);
$date->setFormat('yyyy-MM-dd HH:mm:ss');
$date->setForm($element->getForm());
return $date->getElementHtml();
}
}
在system.xml中使用新的Field类:
<start_date>
<label>Start Date</label>
<frontend_type>text</frontend_type>
[b]<frontend_model>Glamour_Glscore_Block_Adminhtml_System_Config_Date</frontend_model>[/b]
<validate>validate-date</validate>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</start_date>
(责任编辑:最模板) |