项目作者: d1soft

项目描述 :
Yii2 widget for ElFinder
高级语言: PHP
项目地址: git://github.com/d1soft/yii-elfinder.git
创建时间: 2018-05-06T12:34:40Z
项目社区:https://github.com/d1soft/yii-elfinder

开源协议:MIT License

下载


elFinder file manager for Yii 2

This extension integrates an elFinder 2.1 file manager into
Yii framework 2.0. It is version with added editors src to Asset.

Latest Stable Version
Total Downloads
License
Build Status

Installation

Install extension through composer:

  1. composer require d1soft/yii2-elfinder

Usage

Configure actions

For using elFinder you must create and configure controller. See complete example with actions for elFinder’s connector,
InputFile widget, CKEditor filebrowser* options and TinyMCE file_picker_callback option:

  1. <?php
  2. namespace app\controllers;
  3. use d1soft\elfinder\CKEditorAction;
  4. use d1soft\elfinder\ConnectorAction;
  5. use d1soft\elfinder\InputFileAction;
  6. use d1soft\elfinder\TinyMCEAction;
  7. use Yii;
  8. use yii\web\Controller;
  9. class ElfinderController extends Controller
  10. {
  11. public function actions()
  12. {
  13. return [
  14. 'connector' => [
  15. 'class' => ConnectorAction::className(),
  16. 'options' => [
  17. 'roots' => [
  18. [
  19. 'driver' => 'LocalFileSystem',
  20. 'path' => Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'uploads',
  21. 'URL' => Yii::getAlias('@web') . '/uploads/',
  22. 'mimeDetect' => 'internal',
  23. 'imgLib' => 'gd',
  24. 'accessControl' => function ($attr, $path) {
  25. // hide files/folders which begins with dot
  26. return (strpos(basename($path), '.') === 0) ?
  27. !($attr == 'read' || $attr == 'write') :
  28. null;
  29. },
  30. ],
  31. ],
  32. ],
  33. ],
  34. 'input' => [
  35. 'class' => InputFileAction::className(),
  36. 'connectorRoute' => 'connector',
  37. ],
  38. 'ckeditor' => [
  39. 'class' => CKEditorAction::className(),
  40. 'connectorRoute' => 'connector',
  41. ],
  42. 'tinymce' => [
  43. 'class' => TinyMCEAction::className(),
  44. 'connectorRoute' => 'connector',
  45. ],
  46. ];
  47. }
  48. }

Reed elFinder docs to configure
connector options.

InputFile widget

Example of InputFile widget with enabled mime filter and preview:

  1. <?= d1soft\elfinder\InputFile::widget([
  2. 'name' => 'attributeName',
  3. 'clientRoute' => 'elfinder/input',
  4. 'filter' => ['image'],
  5. 'preview' => function ($value) {
  6. return yii\helpers\Html::img($value, ['width' => 200]);
  7. },
  8. ]) ?>

Note 1: Filter option is using to display only certain files based on their mime type. Check onlyMimes option
in elFinder docs.

Note 2: Preview displays only predefined (saved earlier) input value and not updating on the fly after new selection.

If you want to use the InputFile widget in ActiveForm, it can be done like this:

  1. <?= $form->field($model, 'attributeName')
  2. ->widget(d1soft\elfinder\InputFile::className(), [
  3. 'clientRoute' => 'elfinder/input',
  4. ]) ?>

Using textarea instead text input (can be useful with enabled multiple selection):

  1. <?= d1soft\elfinder\InputFile::widget([
  2. 'name' => 'attributeName',
  3. 'clientRoute' => 'elfinder/input',
  4. 'textarea' => true,
  5. 'textareaRows' => 3, // default is 5
  6. ]) ?>

Enable multiple selection to select more then one file in one input:

  1. <?= d1soft\elfinder\InputFile::widget([
  2. 'name' => 'attributeName',
  3. 'clientRoute' => 'elfinder/input',
  4. 'multiple' => true,
  5. ]) ?>

Default paths separator for text input is comma and newline character for textarea.
You can change them in InputFileAction configuration:

  1. class ElfinderController extends Controller
  2. {
  3. public function actions()
  4. {
  5. return [
  6. // ...
  7. 'input' => [
  8. 'class' => InputFileAction::className(),
  9. 'connectorRoute' => 'connector',
  10. 'separator' => ',',
  11. 'textareaSeparator' => '\n', // newline character in javascript
  12. ],
  13. // ...
  14. ];
  15. }
  16. }

Integration with CKEditor

For using elFinder with CKEditor widget (like this one) you need to
specify options filebrowserBrowseUrl and (or) filebrowserImageBrowseUrl:

  1. <?= d1soft\ckeditor\CKEditor::widget([
  2. 'name' => 'attributeName',
  3. 'clientOptions' => [
  4. // ...
  5. 'filebrowserBrowseUrl' => yii\helpers\Url::to(['elfinder/ckeditor']),
  6. 'filebrowserImageBrowseUrl' => yii\helpers\Url::to(['elfinder/ckeditor', 'filter' => 'image']),
  7. ],
  8. ]) ?>

Note: For filebrowserImageBrowseUrl we use filter query param to display only images.

Integration with TinyMCE 4

For using elFinder with TinyMCE 4 widget (like this one) you need to
specify option file_picker_callback:

  1. <?= d1soft\tinymce\TinyMce::widget([
  2. 'name' => 'attributeName',
  3. 'clientOptions' => [
  4. // ...
  5. 'file_picker_callback' => d1soft\elfinder\TinyMCE::getFilePickerCallback(['elfinder/tinymce']),
  6. ],
  7. ]) ?>

Note: option file_picker_callback available since 4.1.0 version of TinyMCE js plugin.

With second param in getFilePickerCallback() you can set additional tinymce.WindowManager.open settings:

  1. TinyMCE::getFilePickerCallback(['elfinder/tinymce'], ['width' => 1200, 'height' => 600])

Standalone file manager

Add ElFinder widget to any view:

  1. <?= d1soft\elfinder\ElFinder::widget([
  2. 'connectorRoute' => ['elfinder/connector'],
  3. 'settings' => [
  4. 'height' => 640,
  5. ],
  6. 'buttonNoConflict' => true,
  7. ]) ?>

Note: If you are using Bootstrap 3 enable buttonNoConflict option to resolve conflict between
Bootstrap and jQuery UI buttons.