Yii2整合百度编辑器UEditor

编辑器使用:https://github.com/BigKuCha/yii2-ueditor-widget

安装:
$ php composer.phar require kucha/ueditor "*"
或修改composer.json,添加"kucha/ueditor": "*",使用composer update来安装。
或下载文档,放置于vendor目录,修改autoload_psr4.php添加:'kucha\\ueditor\\' => array($vendorDir . '/kucha/ueditor'),

使用方法:

控制器:\controllers\IndexController.php

<?php
namespace app\controllers;
use yii\web\Controller;
use app\models\Index;
use Yii;

class IndexController extends Controller{
    public function actions(){
        return [
            'upload' => [
                'class' => 'kucha\ueditor\UEditorAction',
                'config' => [
                    "imageUrlPrefix"  => Yii::$app->request->hostInfo,//图片访问路径前缀
                    "imagePathFormat" => Yii::getAlias("@web"). "/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", //上传保存路径
                ],
            ]
        ];
    }
    public function actionIndex(){

        $model = new Index;
        return $this->render('index', ['model'=>$model]);
    }
}

模型:\models\Index.php

<?php
namespace app\models;
use yii\db\ActiveRecord;

class Index extends ActiveRecord{

    public $colum;

    public static function tableName(){
        return "{{ic_project}}";
    }
}

视图:\view\index\index.php

<?php 
    use yii\bootstrap\ActiveForm;
?>


<?php $form = ActiveForm::begin(); ?>

<?php echo $form->field($model,'colum')->widget('kucha\ueditor\UEditor',[
    'clientOptions' => [
        //编辑区域大小
        'initialFrameHeight' => '200',
        //设置语言
        'lang' =>'zh-cn', //中文为 zh-cn en
        //定制菜单
        /*'toolbars' => [
            [
                'fullscreen', 'source', 'undo', 'redo', '|',
                'fontsize',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'removeformat',
                'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|',
                'forecolor', 'backcolor', '|',
                'lineheight', '|',
                'indent', '|'
            ],
        ]*/
    ]
]); ?>

<?php ActiveForm::end(); ?>

Tags: yii

仅有一条评论

  1. 文件保存路径为 web\upload

添加新评论