yii2.0 引入Ueditor [ 2.0 版本 ]
1、在入口文件【index.php】目录下新建public目录和uploads目录,下载ueditor,解压到public目录下;
2、在ueditor/php/config.json中自定义上传目录;将编辑器上传目录指定到/uploads/ueditor;
如"imagePathFormat": "/uploads/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"scrawlPathFormat": "/uploads/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}"
3、在视图中引入ueditor相关js文件,指定要渲染的textarea;
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
//引入百度编辑器
$this->registerJsFile('@web/public/ueditor/ueditor.config.js');//注册自定义js
$this->registerJsFile('@web/public/ueditor/ueditor.all.min.js');
$this->registerJsFile('@web/public/ueditor/lang/zh-cn/zh-cn.js');
?>
<script>
$(function(){
var ue = UE.getEditor('editor');
})
</script>
<style>
.inline .radio,.inline .checkbox{display: inline-block;margin: 0 5px;}
#editor{margin-top: 20px;padding:0;margin:20px 0;width:100%;height:auto;border: none;}
</style>
<?php $form=ActiveForm::begin([
'id'=>'upload',
'enableAjaxValidation' => false,
'options'=>['enctype'=>'multipart/form-data']
]);
?>
<?= $form->field($model,'title')->textInput();?>
<?= $form->field($model, 'image')->fileInput();?>
<?= $form->field($model,'content')->textarea(['rows'=>6,'id'=>'editor','class'=>'col-sm-1 col-md-12']);?>
<?= Html::submitButton('提交', ['class'=>'btn btn-primary','name' =>'submit-button']) ?>
<?php ActiveForm::end();?>
4、大功告成,可以开始测试编辑器功能了,编辑器样式按需求设置即可>
zfeig
注册时间:2014-07-29
最后登录:2015-09-29
在线时长:36小时6分
最后登录:2015-09-29
在线时长:36小时6分
- 粉丝55
- 金钱75
- 威望30
- 积分735
共 5 条评论
https://github.com/liucunzhou/yii2-ueditor
这个是小弟写的百度编辑器扩展。
有什么特色呢?怎么获取getFileInfo()返回的json?
没有效果..............
编辑器提交不了内容
用不了啊 还是那样白白的没有用
yii2 UEditor 提示无法找到类 这个怎么解决啊。重新安装了框架,重新安装了Ueditor也不行!