Yii2.0 引入Ueditor流程和其他框架不同
必须引入Ueditor for Yii2.0,否则不能正常使用
1,composer下载
composer require kucha/ueditor "*"
2,控制器
public function actions() { return [ 'upload' => [ 'class' => 'kucha\ueditor\UEditorAction', ] ]; }
3.视图
$form->field($model,'xxx')->widget('kucha\ueditor\UEditor',[]); 或者 echo \kucha\ueditor\UEditor::widget(['name' => 'xxxx']);
视图中可以更改默认前端样式
举个例子
<?= $form->field($model,'contract_content')->widget('kucha\ueditor\UEditor',[ 'clientOptions' => [ //编辑区域大小 'initialFrameHeight' => '200', //设置语言 'lang' =>'en', //中文为 zh-cn 'elementPathEnabled'=>false, //定制菜单 'toolbars' => [ [ 'fullscreen', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'cleardoc', '|', 'lineheight', '|', 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|', 'directionalityltr', 'directionalityrtl', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'link', 'unlink', 'anchor', '|', ], ], ] ]); ?>
5,如需文件上传,请按照config示例修改
public function actions() { return [ 'upload' => [ 'class' => 'kucha\ueditor\UEditorAction', 'config' => [ "imageUrlPrefix" => "http://www.baidu.com",//图片访问路径前缀 "imagePathFormat" => "/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}" //上传保存路径 "imageRoot" => Yii::getAlias("@webroot"), ], ] ]; }