当前位置: 首页 > 工具软件 > Redactor > 使用案例 >

Yii 安装富文本插件:redactor

周苑博
2023-12-01
  1. 下载插件

    php composer.phar require --prefer-dist yiidoc/yii2-redactor "*"
    
  2. 修改 Yii 的配置文件: config/web.php

     'modules' => [
            'redactor' => [
                'class' => 'yii\redactor\RedactorModule',
                'uploadDir' => '@webroot/path/to/uploadfolder',
                'uploadUrl' => '@web/path/to/uploadfolder',
                'imageAllowExtensions'=>['jpg','png','gif']
            ],
        ],
    
  3. 添加控制器: controllers/EditorController.php

    <?php
    namespace app\controllers;
    
    use yii\web\Controller;
    
    class EditorController extends Controller
    {
        public function actionRedActor()
        {
            return $this->render('redactor');
        }
    }
    
  4. 添加视图文件: 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']
        ]
    ]) ?>
    
  5. 路由访问

    http://localhost:8080/index.php?r=editor/red-actor

[1] Github for yiidoc/yii2-redactor
[2] Document for redactor

 类似资料: