andrewdanilov / yii2-input-images
Input images widget
Installs: 207
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.6.0
- andrewdanilov/yii2-fontawesome: ~1.0.0
- mihaildev/yii2-elfinder: *@dev
- yiisoft/yii2: ^2.0.0
README
Widget building form fields for uploading single or multiple images. It extends and requires extension MihailDev/yii2-elfinder
Installation
The preferred way to install this extension is through composer.
Either run
composer require andrewdanilov/yii2-input-images "~1.0.0"
or add
"andrewdanilov/yii2-input-images": "~1.0.0"
to the require section of your composer.json
file.
Usage
For frontend
In your config/main.php add:
return [ // ... 'controllerMap' => [ 'upload' => [ 'class' => 'andrewdanilov\InputImages\UploadController', 'path' => 'upload/post/images', // path to upload images, default is 'upload/images' ], ], ];
Then in view just add a widget call:
<?php use andrewdanilov\InputImages\InputImagesFrontend; ?> <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'logo')->widget(InputImagesFrontend::class) ?> <?php ActiveForm::end(); ?>
For backend
In your config/main.php add:
return [ // ... 'controllerMap' => [ 'elfinder' => [ 'class' => 'mihaildev\elfinder\Controller', 'access' => ['admin'], 'roots' => [ [ 'baseUrl' => '', 'basePath' => '@frontend/web', 'path' => 'upload/images', 'name' => 'Изображения', ], ], ], ], ];
And then add form in your view:
<?php use andrewdanilov\InputImages\InputImages; ?> <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'logo')->widget(InputImages::class) ?> <?php ActiveForm::end(); ?>