标签(空格分隔): Yii2
1 安装
$ [ahcj@localhost basic9] composer require pjkui/kindeditor "dev-master" -vvv
2 使用方法
1.1 修改控制器,增加上传方法
新建 backend/web/upload,然后修改 backend\controllers\NewsController,增加以下代码.
public function actions(){
return [
'Kupload' => [
'class' => 'pjkui\kindeditor\KindEditorAction',
]
];
}
1.2 修改视图
field($model, 'title')->textInput(['maxlength' => true]) ?>
field($model, 'content')->widget( KindEditor::className(),['clientOptions'=>['allowFileManager'=>'true','allowUpload'=>'true']]) ?>
isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
3 配置
编辑器相关配置,请在view
中配置,参数为clientOptions,比如定制菜单,编辑器大小等等,具体参数请查看KindEditor官网文档。
3.1 配置为富文本编辑器,默认配置
field($model, 'content')->widget('pjkui\kindeditor\Kindeditor',['clientOptions'=>['allowFileManager'=>'true','allowUpload'=>'true']]) ?>
3.2 配置kindeditor为上传文件按钮,可以自动上传文件到服务器
field($model, 'article_pic')->widget('pjkui\kindeditor\Kindeditor',['clientOptions'=>['allowFileManager'=>'true','allowUpload'=>'true'],'editorType'=>'uploadButton]) ?>
3.3 配置kindeditor为取色器
field($model, 'content')->widget('pjkui\kindeditor\Kindeditor','editorType'=>'colorpicker']) ?>
3.4 配置kindeditor为文件管理器,可以查看和选着其上传的文件。
field($model, 'article_pic')->widget('pjkui\kindeditor\Kindeditor',['clientOptions'=>['allowFileManager'=>'true','allowUpload'=>'true'],'editorType'=>'file-manager']) ?>
3.5 配置kindeditor为图片上传对话框。
usage:
field($model, 'article_pic')->widget('pjkui\kindeditor\Kindeditor',['clientOptions'=>['allowFileManager'=>'true','allowUpload'=>'true'],'editorType'=>'image-dialog']) ?>
3.6 配置kindeditor为文件上传对话框。
usage:
field($model, 'article_pic')->widget('pjkui\kindeditor\Kindeditor',['clientOptions'=>['allowFileManager'=>'true','allowUpload'=>'true'],'editorType'=>'file-dialog']) ?>
3.7 Demo
use \pjkui\kindeditor\KindEditor;
echo KindEditor::widget([
'clientOptions' => [
'height' => '500',
//定制菜单
'items' => [
'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor', 'link', 'unlink', '|', 'about'
],
]);