2

製品のように複数の画像をアップロードできるカスタム モジュールを作成したいのですが、カスタム モジュールを 1 つ作成しましたが、画像が 1 つしかアップロードされません。

フォーム.php

$fieldset->addField('filename', 'image', array(
     'label'     => Mage::helper('footertop')->__('File'),
     'name'      => 'filename',

  ));
4

1 に答える 1

2

画像フィールド用のカスタム レンダラーを作成する必要があると思います。このために、モジュールに次のクラスを作成します。

class [YOURNamespace]_[YOURModule]_Block_Adminhtml_[YOUREntity]_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', '[YOURNamespace]_[YOURModule]_Block_Adminhtml_[YOUREntity]_Helper_Image');

または、「政治的に正しく」なりたい場合は、次のように追加します。

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

これにより、現在のフィールドセットで、イメージ タイプのすべてのフィールドを独自のクラスでレンダリングする必要があることが Magento に通知されます。

これで、同じようにフィールドを追加できます。

$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('YOURmodule')->__('Select Image'),
        'title'     => Mage::helper('YOURmodule')->__('Can select multiple images'),
        'required'  => true,
        'disabled'  => $isElementDisabled
    ));

それでおしまい。プレースホルダー ([YOURModule] など) を自分の値に置き換えることを忘れないでください。

于 2014-05-14T11:35:21.493 に答える