Ueditor是百度开发出来的富文本编辑器,平时也比较喜欢用这个,感觉比国外的CKEditor,FCKEditor样式看起来好多了。Yii中引入ueditor有很多种方法,Yii中也有专门的扩展供使用,下面说下我是怎么使用的。
1.Ueditor Download(下载地址:http://ueditor.baidu.com/build/build_down.php?t=1_2_1_0-utf8-php),下载后解压到对应的项目的根目录下,比如项目是admin,那么就将ueditor解压到admin/ueditor
2.Ueditor extension download,下载ueditor扩展,这是Yii引入ueditor所需要的,下载地址:http://www.yiiframework.com/extension/ueditor-extension-for-yii/files/UEditor-with-default-config.zip
下载完成后解压到Yii的protected/extension下面,即解压后的路径为admin/protected/extension/ueditor
3.视图中引入:
<?php $this->widget('ext.ueditor.UEditor', array( 'id'=>'editor', 'model'=>$content, 'attribute'=>'content', 'UEDITOR_CONFIG'=>array( 'UEDITOR_HOME_URL'=>Yii::app()->baseUrl.'/ueditor/', //ueditor的路径 'p_w_picpathUrl'=>Yii::app()->baseUrl.'/ueditor/php/p_w_picpathUp.php', //上传的图片提交给的处理程序路径 'p_w_picpathPath'=>Yii::app()->baseUrl.'/ueditor/php/', //上传图片保存路径 'emotionLocalization'=>true, 'pageBreakTag'=>'[page]', 'width'=>'800px', 'height'=>'400px', 'initialContent'=>'', 'toolbars'=>array( //这里是自定义工具条 array( 'fontfamily', 'fontsize', 'forecolor', 'backcolor','|', 'directionalityltr', 'directionalityrtl', '|', '', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch','autotypeset', '|', 'blockquote', '|', 'pasteplain', '|', 'insertorderedlist', 'insertunorderedlist','selectall', 'cleardoc', '|', 'customstyle', 'paragraph', '|','rowspacingtop', 'rowspacingbottom','lineheight', '|', 'link', 'unlink', 'anchor', '|', 'p_w_picpathnone', 'p_w_picpathleft', 'p_w_picpathright', 'p_w_picpathcenter', '|', 'insertp_w_picpath', 'emotion', 'insertvideo', 'p_w_upload',), ), ))); ?>
注:有时候一个页面需要引入多个ueditor,这样的话只需要修改对应的id就行了。
转载于:https://blog.51cto.com/php2013/1359883