alex290 / yii2-widget-gallery
Yii2 Widget gallery
Installs: 26
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Language:JavaScript
Type:yii2-extension
Requires
- alex290/yii2-images: *
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2025-02-14 21:22:16 UTC
README
Yii2 Widget gallery
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist alex290/yii2-widget-gallery "*"
or add
"alex290/yii2-widget-gallery": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by :
в конфиге web.php прописать
'modules' => [
'widget-gallery' => [
'class' => 'alex290\widgetgallery\Module',
'path' => 'upload', //path to files
],
],
run migrate
php yii migrate/up --migrationPath=@vendor/alex290/yii2-widget-gallery/migrations
attach behaviour to your model (be sure that your model has "id" property)
public function behaviors()
{
return [
'gallery' => [
'class' => 'alex290\widgetgallery\behaviors\Behave',
]
];
}
Вывести виджет в админке
<?= $model->getGalleryAdmin($title = 'Название', $desc = 'Описание') ?>
$title = false
Скрывает поле $title
$desc = false
Скрывает поле $desc
Добавить к модели новые изображения
$model->attachGellery([
'../../image.png',
'../../image1.png',
//...
]);
Изменить данные в объекте галереи
$model->updateGalleryItem($id, $title = 'Заголовок', $desc = 'Описание');
$title и $desc - Необязательны
Получить массив объектов виджетов данной модели
$model->getGallery();
В контролле для загрузки или изменения данных
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->getNewImages()->upload($model);
...
}
Удалить виджеты
$model->removeGalleryAll();
$model->removeGalleryItem($id);
Выводить записи на странице
<?php if ($model->getGallery() != null) : ?>
<?php foreach ($model->getGallery() as $key => $gallery) : ?>
<?php endforeach ?>
<?php endif ?>