如何创建一个以上的单个文件上传单击实体的“添加字段"按钮,并在magento中为新属性选择类型“文件" [英] How to create More than one single file upload Click the 'Add field' button for entity and select type 'file' for the new attribute in magento
本文介绍了如何创建一个以上的单个文件上传单击实体的“添加字段"按钮,并在magento中为新属性选择类型“文件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建Magento管理员自定义模块,请点击添加字段按钮以为实体选择新属性的类型文件"
How to create Magento admin custom module click add field button for entity select type 'file' for the new attribute
这是表单代码:
$fieldset->addField('uploadpdf', 'file', array(
'label' => Mage::helper('promotionsoffers')->__('Upload PDF'),
'name' => 'uploadpdf',
));`
推荐答案
这是要通过Magento的表单库实现类似功能,我们将以这种方式对其代码进行一些修改
To achieve similar through Magento's Form Library, we will modify its code a bit in this way
修改lib/Varien/Data/Form/Element/Abstract.php的getElementHtml
方法
Modify getElementHtml
method of lib/Varien/Data/Form/Element/Abstract.php
public function getElementHtml()
{
if($this->getType()=='file' && $this->getMultiple())
$_multiple = ' multiple';
$html = '<input id="'.$this->getHtmlId().'" name="'.$this->getName()
.'" value="'.$this->getEscapedValue().'" '.$this->serialize($this->getHtmlAttributes()).$_multiple.'/>'."\n";
$html.= $this->getAfterElementHtml();
return $html;
}
,然后像这样在字段声明中传递新属性multiple=>true
and then just pass new attribute multiple=>true
in you field declaration like this
$fieldset->addField('uploadpdf', 'file', array(
'label' => Mage::helper('promotionsoffers')->__('Upload PDF'),
'name' => 'uploadpdf[]',
'multiple'=>true
));
这篇关于如何创建一个以上的单个文件上传单击实体的“添加字段"按钮,并在magento中为新属性选择类型“文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文