andrewdanilov/yii2-input-images

Input images widget

1.0.6 2021-06-20 08:34 UTC

This package is auto-updated.

Last update: 2024-04-22 04:19:52 UTC


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(); ?>