magento如何在管理面板网格表格中上传多个图像?

在这里,我想在magento中以管理面板网格形式上传多个图像。我以管理面板网格形式创建图像上传。这里我附上了我的图片上传编码。

[....]

$fieldset->addField('image', 'image', array(
            'name'      => 'image',
            'label'     => Mage::helper('magentostudy_design')->__('design Image'),
            'title'     => Mage::helper('magentostudy_design')->__('design Image'),
            'required'  => true,
            'disabled'  => $isElementDisabled
        ));
[....]

当我使用此参数更改多个上传图像时。'multiple'=> 'multiple' 这是我的代码:

 [....]

    $fieldset->addField('image', 'image', array(
                'name'      => 'image',
                'multiple'  => 'multiple',
                'mulitple'  => true,
                'label'     => Mage::helper('magentostudy_design')->__('design Image'),
                'title'     => Mage::helper('magentostudy_design')->__('design Image'),
                'required'  => true,
                'disabled'  => $isElementDisabled
            ));
    [....]

而且我把名称值作为数组[]就像这样'name' => 'image[]',。不,我没有得到任何结果,仍然会上传单张图片。如何在magento中创建多个图像上传概念

您需要为图像字段创建自定义渲染器。为此,在您的模块中创建此类:

<?php 
class [Namespace]_[Module]_Block_Adminhtml_[Entity]_Helper_Image extends Varien_Data_Form_Element_Image{
    //make your renderer allow "multiple" attribute
    public function getHtmlAttributes(){
        return array_merge(parent::getHtmlAttributes(), array('multiple'));
    }
}

现在位于您_prepareForm(添加字段的位置)的顶部,在添加任何字段之前添加此行:

$fieldset->addType('image', '[Namespace]_[Module]_Block_Adminhtml_[Entity]_Helper_Image');

或者如果你想要“ politically correct ”,可以这样添加:

$fieldset->addType('image', Mage::getConfig()->getBlockClassName('[module]/adminhtml_[entity]_helper_image'));

这将告诉Magento在您当前的fieldset中,所有具有类型的字段image都应该由您自己的类呈现。

现在,您可以像添加字段一样添加字段:

$fieldset->addField('image', 'image', array(
            'name'      => 'image[]', //declare this as array. Otherwise only one image will be uploaded
            'multiple'  => 'multiple', //declare input as 'multiple'
            'label'     => Mage::helper('magentostudy_design')->__('design Image'),
            'title'     => Mage::helper('magentostudy_design')->__('design Image'),
            'required'  => true,
            'disabled'  => $isElementDisabled
        ));

而已。
不要忘记[Module]用您的值替换占位符(和其他)。
[编辑]
这基本上是覆盖/添加所需输入类型的方法。创建自己的类,应该扩展原始输入类(或者Varien_Data_Form_Element_Abstract如果添加一个新类)并在顶部声明它_prepareForm

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论