Home > Backend Development > PHP Tutorial > Yii2.0 integrates elfinder picture manager calling method

Yii2.0 integrates elfinder picture manager calling method

伊谢尔伦
Release: 2023-03-02 20:32:01
Original
2373 people have browsed it

Yii2 extension: https://github.com/MihailDev/yii2-elfinder
Although the tutorial is in Russian, don’t be afraid, just follow the code
Steps:
1. Use composer to install the extension
composer require --prefer-dist mihaildev/ yii2-elfinder "*"

2. Add configuration information. I am Yii2 advanced template, used in the background, so open the backend/config/main.php configuration file
Add it at the same level as 'components'

'controllerMap' => [ 'elfinder' => [ 'class' => 'mihaildev\elfinder\PathController', 'access' => ['@'], 'root' => [ 'path' => 'uploads', //主目录路径 'name' => 'Files' ],/*
        'watermark' => [
            'source'         => __DIR__.'/logo.png', // Path to Water mark image
            'marginRight'    => 5,          // Margin right pixel
            'marginBottom'   => 5,          // Margin bottom pixel
            'quality'        => 95,         // JPEG image save quality
            'transparency'   => 70,         // Water mark image transparency ( other than PNG )
            'targetType'     => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field )
            'targetMinPixel' => 200         // Target image minimum pixel size
        ]*/ ]
],
Copy after login

3. Add Default parameters
Open commmon(backend)/config/params.php

// elfinder默认配置 'elfinderDefaultConfig' => [ 'language' => 'zh_CN', 'controller' => 'elfinder', // 默认控制名 'filter' => 'image', 
// 只管理图片 https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes &#39;template&#39; => &#39;<div class="input-group">{input}
<span class="input-group-btn">{button}</span></div>&#39;, &#39;options&#39; => [&#39;class&#39; => &#39;form-control&#39;], &#39;buttonOptions&#39; => 
[&#39;class&#39; => &#39;btn btn-default&#39;], &#39;buttonName&#39; => &#39;浏览&#39; ],
Copy after login

4. The last step is to introduce the call

Open the form view file to be used and add the following code

use mihaildev\elfinder\InputFile; <?php $path = &#39;carLogo&#39;; // 存放目录,改为实际的,elfinder会自动创建 
$elfinderConfig = array_merge(Yii::$app->params[&#39;elfinderDefaultConfig&#39;],[&#39;path&#39; => $dir]); echo $form->field($model, &#39;carLogo&#39;)->widget(InputFile::className(),$elfinderConfig); ?>
Copy after login

Final effect:

Yii2.0 integrates elfinder picture manager calling method

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template