功能介绍:今天要做一个后台表单元素显示出日期时间,开始以为跟magento后台用到的表单元素标签(1)的功能一样,只需要设置type类型设置为date就可,但是设置了,开始怎么也弄不出来,又想着在后台加载一些js包,引用外部的js插件来实现这个功能,后来请教公司技术牛人,说可以直接调用magento系统自带的就可以,这里记录下如何实现这个功能,效果图如下:
代码如下,在form.php中增加代码如下:
$fieldset->addfield( 'endtime', 'date',//type类型 array( 'label' => mage::helper('blog')->__('endtime'), 'required' => true,//是否为必选项 'name' => 'endtime', 'image' => $this->getskinurl('images/grid-cal.gif'),//增加图标 'format' => mage::app()->getlocale()->getdateformat(mage_core_model_locale::format_type_short),//时间格式));
额外的一些备注:
1.有时候如果想在后台表单加载一些js,也可以在array()中添加:'after_element_html' => 。
2.添加css,可以先在外写好css样式,$style=width:6px;text-align:center;再添加:'style'=> $style,//定义按钮的css 。也可以直接写,例如:'style' => 'width:700px; height:500px;'。
$fieldset->addfield( 'endtime', 'date',//类型,可以为text,datetime,time,submit,select,radio,checkbox,password,link,label,image,file... array( 'label' => mage::helper('blog')->__('endtime'), 'required' => true,//是否为必选项 'style'=> $style,//定义按钮的css . 'name' => 'endtime', 'image' => $this->getskinurl('images/grid-cal.gif'),//添加图片 'format' => mage::app()->getlocale()->getdateformat(mage_core_model_locale::format_type_short), 'after_element_html' => 。 ));
以上就介绍了magento后台表单元素标签2--显示日期,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。