开发者

Magento: Add images (or any attribute) to custom module

开发者 https://www.devze.com 2023-01-29 01:06 出处:网络
I\'m building a custom module and I need to be able to add an image to my data type much like we can add images to products. From what I learned, an image is simply an attribute.

I'm building a custom module and I need to be able to add an image to my data type much like we can add images to products. From what I learned, an image is simply an attribute.

How do I add a tab to my module's edit page where the image upload functionality is provided and the uploaded images are automatically associated to my data type entries?

Please note that I know how to add the tabs and even upload an image in plain PHP. I would just like to re-use the functionality that Products already have and 开发者_开发技巧do things the Magento way.


If you install and use the Module Creator extension, that will give you a file upload functionality that you can use for images. You can then change the field type in the adminhtml to be "image" rather than "file" to give you a thumbnail of the uploaded file in the Edit tab. e.g. in DOCROOT\app\code\local\Namespace\Modulename\Block\Adminhtml\News\Edit\Tab\Form.php

$fieldset->addField('image_filename', 'image', array(
      'label'     => Mage::helper('news')->__('Top Left Photo'),
      'required'  => false,
      'name'      => 'image_filename',
      'note'      => Mage::helper('news')->__('Image must be 400x235 dimensions'),
  ));

The admin controller created by the ModuleCreator will handle all the image upload code for you.

Cheers, JD

0

精彩评论

暂无评论...
验证码 换一张
取 消