ImageAttachment ¶
This extension intended to handle actions with images associated with model.
Extensions provides user friendly widget, to upload and remove image.
Screenshots:
Features ¶
- Asynchronous image upload
- Ability to generate few image versions with different configurations
- Drag & Drop
Decencies ¶
- Yii
- Twitter bootstrap
- yii-image component
Installation: ¶
0. Download and extract extension somewhere in your application(in this guide into extensions/imageAttachment). Also available in composer.
- Add ImageAttachmentBehavior to you model, and configure it, create folder for uploaded files.
public function behaviors()
{
return array(
'preview' => array(
'class' => 'ext.imageAttachment.ImageAttachmentBehavior',
// size for image preview in widget
'previewHeight' => 200,
'previewWidth' => 300,
// extension for image saving, can be also tiff, png or gif
'extension' => 'jpg',
// folder to store images
'directory' => Yii::getPathOfAlias('webroot').'/images/productTheme/preview',
// url for images folder
'url' => Yii::app()->request->baseUrl . '/images/productTheme/preview',
// image versions
'versions' => array(
'small' => array(
'resize' => array(200, null),
),
'medium' => array(
'resize' => array(800, null),
)
)
)
);
}
- Add ImageAttachmentAction in controller somewhere in your application. Also on this step you can add some security checks for this action.
class ApiController extends Controller
{
public function actions()
{
return array(
'saveImageAttachment' => 'ext.imageAttachment.ImageAttachmentAction',
);
}
}
- Add ImageAttachmentWidget somewhere in you application, for example in editing from.
$this->widget('ext.imageAttachment.ImageAttachmentWidget', array(
'model' => $model,
'behaviorName' => 'preview',
'apiRoute' => 'api/saveImageAttachment',
));
- It is done! You can use it now.
if($model->preview->hasImage())
echo CHtml::image($model->preview->getUrl('medium'),'Medium image version');
else
echo 'no image uploaded';
Contributing ¶
Pull requests are welcome! Also, if you any ideas or questions about - welcome to issue tracker
Resources ¶
Example application - it is fork from yii blog demo, with some of my extensions.
Changelog ¶
- December 2, 2013 - update documentation, added min size for preview, fix bug with photo removal, on some urlManager configurations, bug fix for directory creation, fixes in updateImages method.
- September 4, 2013 - Fix bugs: when using model with composite key, with automatic directory creation
bug in doc
rename previewImageAttachmentBehavior -> preview ?
thanks, looks great!
should also doc how to see correct buttons using yii-bootstrap instead of a bootstrap theme itself
Re: bug in doc
Thanks - fixed behavior name in doc. About yii-bootstrap - "bootstrap.css" is the only thing you need from it in order to use this extension
Nice!
Look nice! Do this ext. have multiload images support? If no, why?
re: have multiload images support? If no, why?
No, there is only one image... So no need in multiupload.
Or you meant something else?
i always just see "Before image upload. Save this"
Hi there, I am having trouble installing. I followed all the steps. I am confused however, about the dependency yii-image component. How should I install this, do I need to?
re: i always just see "Before image upload. Save this"
Hi, yes - you should install "image" component.
I have added it to downloads, and added link to it into extension description.
Also I have added link to application with example how to use this extension.
thanks
Thanks, good extension. Multiupload support would be a great feature. I know we can use your other extension GalleryManager but sometimes is too much for some specific projects.
i always just see "Before image upload. Save this"
I'm having the same problem.
I downloaded imageAttachment and image extensions.
I extracted imageAttachment on /protected/imageAttachment and imagem on /protected/imageAttachment/image
Then I added the following in main
'components'=>array( 'image'=>array( 'class'=>'application.extensions.image.CImageComponent', 'driver'=>'GD', ), );
and did everything you said on this page. What else should I do?
Re: i always just see "Before image upload. Save this"
Problem is not with yii-image extension.
This message appears because you can not upload images for new model, try to save it before using image-attachement extension.
Re: i always just see "Before image upload. Save this"
My image model is like this
ImageId, Name, ImageLocation, Caption, Productid
Also what it means by " try to save it before using image-attachement extension." How can I save a model?
$this->model->isNewRecord
What do I need to do exactly to get it working?
Thx
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.