dev-master
9999999-devYii2 filemanager
GNU GPLv2
The Requires
- yiisoft/yii2 *
- yiisoft/yii2-imagine *
- pendalf89/yii2-tinymce *
- kartik-v/yii2-widget-alert *
- weison-tech/yii2-file-upload-widget *
by PendalF
Yii2 filemanager
This module provide interface to collect and access all mediafiles in one place. Inspired by WordPress file manager., (*1)
, (*2)
, (*3)
, (*4)
, (*5)
, (*6)
, (*7)
, (*8)
The preferred way to install this extension is through composer., (*9)
Either run, (*10)
php composer.phar require --prefer-dist weison-tech/yii2-filemanager "*"
or add, (*11)
"weison-tech/yii2-filemanager": "*"
to the require section of your composer.json
file., (*12)
Apply migration, (*13)
yii migrate --migrationPath=vendor/weison-tech/yii2-filemanager/migrations
Configuration:, (*14)
'modules' => [ 'filemanager' => [ 'class' => 'pendalf89\filemanager\Module', // Upload routes 'routes' => [ // Base absolute path to web directory 'baseUrl' => '', // Base web directory url 'basePath' => '@frontend/web', // Path for uploaded files in web directory 'uploadPath' => 'uploads', ], // Thumbnails info 'thumbs' => [ 'small' => [ 'name' => 'Мелкий', 'size' => [100, 100], ], 'medium' => [ 'name' => 'Средний', 'size' => [300, 200], ], 'large' => [ 'name' => 'Большой', 'size' => [500, 400], ], ], ], ],
Simple standalone field:, (*15)
use pendalf89\filemanager\widgets\FileInput; echo $form->field($model, 'original_thumbnail')->widget(FileInput::className(), [ 'buttonTag' => 'button', 'buttonName' => 'Browse', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['class' => 'form-control'], // Widget template 'template' => '{input}{button}', // Optional, if set, only this image can be selected by user 'thumb' => 'original', // Optional, if set, in container will be inserted selected image 'imageContainer' => '.img', // Default to FileInput::DATA_URL. This data will be inserted in input field 'pasteData' => FileInput::DATA_URL, // JavaScript function, which will be called before insert file data to input. // Argument data contains file data. // data example: [alt: "Ведьма с кошкой", description: "123", url: "/uploads/2014/12/vedma-100x100.jpeg", id: "45"] 'callbackBeforeInsert' => 'function(e, data) { console.log( data ); }', ]); echo FileInput::widget([ 'name' => 'mediafile', 'buttonTag' => 'button', 'buttonName' => 'Browse', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['class' => 'form-control'], // Widget template 'template' => '{input}{button}', // Optional, if set, only this image can be selected by user 'thumb' => 'original', // Optional, if set, in container will be inserted selected image 'imageContainer' => '.img', // Default to FileInput::DATA_URL. This data will be inserted in input field 'pasteData' => FileInput::DATA_URL, // JavaScript function, which will be called before insert file data to input. // Argument data contains file data. // data example: [alt: "Ведьма с кошкой", description: "123", url: "/uploads/2014/12/vedma-100x100.jpeg", id: "45"] 'callbackBeforeInsert' => 'function(e, data) { console.log( data ); }', ]);
With TinyMCE:, (*16)
use pendalf89\filemanager\widgets\TinyMCE; = $form->field($model, 'content')->widget(TinyMCE::className(), [ 'clientOptions' => [ 'language' => 'ru', 'menubar' => false, 'height' => 500, 'image_dimensions' => false, 'plugins' => [ 'advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code contextmenu table', ], 'toolbar' => 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code', ], ]); ?>
In model you must set mediafile behavior like this example:, (*17)
use pendalf89\filemanager\behaviors\MediafileBehavior; public function behaviors() { return [ 'mediafile' => [ 'class' => MediafileBehavior::className(), 'name' => 'post', 'attributes' => [ 'thumbnail', ], ] ]; }
Than, you may get mediafile from your owner model. See example:, (*18)
use pendalf89\filemanager\models\Mediafile; $model = Post::findOne(1); $mediafile = Mediafile::loadOneByOwner('post', $model->id, 'thumbnail'); // Ok, we have mediafile object! Let's do something with him: // return url for small thumbnail, for example: '/uploads/2014/12/flying-cats.jpg' echo $mediafile->getThumbUrl('small'); // return image tag for thumbnail, for example: '<img src="/uploads/2014/12/flying-cats.jpg" alt="Летающие коты">' echo $mediafile->getThumbImage('small'); // return url for small thumbnail
Yii2 filemanager
GNU GPLv2