Add Thumbnail for AW_Blog Extension

1.AW_Blog_Block_Manage_Blog_Edit_Form:

protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
‘id’ => ‘edit_form’,
‘action’ => $this->getUrl(‘*/*/save’, array(‘id’ => $this->getRequest()->getParam(‘id’))),
‘method’ => ‘post’,
‘enctype’ => ‘multipart/form-data’
)
);

$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}

2.AW_Blog_Block_Manage_Blog_Edit_Tab_Form:

$fieldset->addField(‘blog_image’, ‘image’, array(
‘name’ => ‘blog_image’,
‘label’ => $this->__(‘Thumbnail’),
‘title’ => $this->__(‘Thumbnail’),
‘note’ => $this->__(‘Thumbnail’),
));

3.AW_Blog_Manage_BlogController:

if ($data = $this->getRequest()->getPost()) {

if(isset($_FILES[‘blog_image’][‘name’]) and (file_exists($_FILES[‘blog_image’][‘tmp_name’]))) {
try {
$uploader = new Varien_File_Uploader(‘blog_image’);
$uploader->setAllowedExtensions(array(‘jpg’,’jpeg’,’gif’,’png’)); // or pdf or anything

$uploader->setAllowRenameFiles(true);

$uploader->setFilesDispersion(false);

$path = Mage::getBaseDir(‘media’) . DS ;

$uploader->save($path, $_FILES[‘blog_image’][‘name’]);

$data[‘blog_image’] = $uploader->getUploadedFileName();

}catch(Exception $e) {

}
}else{
if(isset($data[‘blog_image’][‘delete’]) && $data[‘blog_image’][‘delete’] == 1)
$data[‘blog_image’] = ”;
else
unset($data[‘blog_image’]);

}

4.At last add a new file in you magento database tab aw_blog name it blog_image
5.In you template us this to show the thumbnail:

<img scr=”<?php echo  $this->getUrl(‘media’).$post->getBlogImage();?>”>

That’s all.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s