mmedojevicbg / yii2-smart-image-field
Image upload field for Yii2 forms
Installs: 41
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-12-10 21:19:49 UTC
README
This is replacement of classic file upload HTML form element. Advantages of this field are:
- You don't have to handle file upload yourself. It is encapsulated in ImageUploadAction.
- ImageUploadAction resolves upload name clashes by default.
- If existing model is edited, image field is pre-populated.
- Uploaded image won't be lost if form has validation errors after submit.
- There is a delete image link besides upload button.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist mmedojevicbg/yii2-smart-image-field "dev-master"
or add
"mmedojevicbg/yii2-smart-image-field": "dev-master"
to the require section of your composer.json
file.
Usage
- Attach ImageUploadAction to designated controller
class SiteController extends BaseController { function actions() { return [ 'upload' => [ 'class' => 'mmedojevicbg\SmartImageField\ImageUploadAction', 'uploadsPath' => \Yii::getAlias('@webroot') . '/uploads', 'uploadsUrl' => '/uploads' ] ]; } }
- Utilize SmartImageField inside ActiveForm
echo SmartImageField::widget(['model' => $model, 'attribute' => 'profile_image', 'uploadsHandler' => '/site/upload']);