Commit 3ff61e27991f7d069a52c08f791c712e63aea760
1 parent
f9404a23
Adding basic gallery
Showing
3 changed files
with
9 additions
and
1 deletions
Show diff stats
backend/controllers/ImageController.php
... | ... | @@ -7,6 +7,7 @@ use backend\components\croppers\CropFactory; |
7 | 7 | |
8 | 8 | use Yii; |
9 | 9 | use yii\helpers\FileHelper; |
10 | +use yii\helpers\StringHelper; | |
10 | 11 | use yii\web\Controller; |
11 | 12 | use backend\models\UploadForm; |
12 | 13 | use yii\web\UploadedFile; |
... | ... | @@ -40,6 +41,9 @@ class ImageController extends Controller |
40 | 41 | public function actionGallery() |
41 | 42 | { |
42 | 43 | $files = FileHelper::findFiles(dirname(dirname(__DIR__)) . '/uploads/'); |
44 | + foreach($files as $k => $file) { | |
45 | + $files[$k] = '/uploads/' . StringHelper::basename($file); | |
46 | + } | |
43 | 47 | return $this->render('gallery', ['files' => $files]); |
44 | 48 | } |
45 | 49 | ... | ... |
backend/views/image/gallery.php
... | ... | @@ -7,4 +7,7 @@ use yii\helpers\Html; |
7 | 7 | /* @var $this yii\web\View */ |
8 | 8 | $this->title = 'Image gallery'; |
9 | 9 | ?> |
10 | -<?php print_r($files) ?> | |
10 | + | |
11 | +<?php foreach ($files as $file): ?> | |
12 | +<img height="500px" src="<?= Html::encode($file) ?>"> | |
13 | +<?php endforeach ?> | |
11 | 14 | \ No newline at end of file | ... | ... |
backend/views/image/index.php
... | ... | @@ -7,6 +7,7 @@ use yii\helpers\Html; |
7 | 7 | /* @var $this yii\web\View */ |
8 | 8 | $this->title = 'Image cropper'; |
9 | 9 | ?> |
10 | +<?= Html::a('Gallery', ['image/gallery']) ?> | |
10 | 11 | <?php $form = ActiveForm::begin(['options' => ['enctype'=>'multipart/form-data']]); ?> |
11 | 12 | <?= $form->field($model, 'imageFiles[]')->widget(FileInput::classname(), [ |
12 | 13 | 'options' => ['accept' => 'image/*', 'multiple' => true], | ... | ... |