下载插件
php composer.phar require --prefer-dist yiidoc/yii2-redactor "*"
修改 Yii 的配置文件: config/web.php
'modules' => [
'redactor' => [
'class' => 'yii\redactor\RedactorModule',
'uploadDir' => '@webroot/path/to/uploadfolder',
'uploadUrl' => '@web/path/to/uploadfolder',
'imageAllowExtensions'=>['jpg','png','gif']
],
],
添加控制器: controllers/EditorController.php
<?php
namespace app\controllers;
use yii\web\Controller;
class EditorController extends Controller
{
public function actionRedActor()
{
return $this->render('redactor');
}
}
添加视图文件: views/editor/redactor.php
<?= \yii\redactor\widgets\Redactor::widget([
'model' => null,
'attribute' => 'content',
'clientOptions' => [
'imageManagerJson' => ['/redactor/upload/image-json'],
'imageUpload' => ['/redactor/upload/image'],
'fileUpload' => ['/redactor/upload/file'],
'lang' => 'zh_cn',
'plugins' => ['clips', 'fontcolor','imagemanager']
]
]) ?>
路由访问
http://localhost:8080/index.php?r=editor/red-actor
[1] Github for yiidoc/yii2-redactor
[2] Document for redactor