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
精彩评论