这是别人写的一个yii1的百度编辑器ueditor的扩展,站长我已经用在了自己的项目中,现在记录下用法和使用中出现的问题。
目录结构:
baiduUeditor
|--resource //ueditor资源包
|--views //widget的视图
|--config.php //后端配置文件 包括文件格式 大小 目录 路径 文件名等等
|--UeditorController.php //后端主控制器 可以修改继承类为自定义的基类
|--UeditorWidget.php //widget主要渲染编辑器
|--Uploader.class.php //上传等主要处理类
使用:
1、将baiduUeditor拷贝到protected/extensions/目录下
2、添加以下代码到config/main.php
- 'controllerMap'=>array(
- 'ueditor'=>array(
- 'class'=>'ext.baiduUeditor.UeditorController',
- ),
- ),
如果你想只在某个module里使用,请添加以下代码到modules/moduleName/moduleNameModule.php的init方法中
- $this->controllerMap=array(
- 'ueditor'=>array(
- 'class'=>'ext.baiduUeditor.UeditorController',
- ),
- );
在要显示编辑器的view中放置如下代码
- $this->widget('ext.baiduUeditor.UeditorWidget',
- array(
- 'id'=>'article_content',//容器的id 唯一的[必须配置]
- 'name'=>'content',//post到后台接收的name [必须配置]
- 'content'=>'',//初始化内容 [可选的]
- //配置选项,[可选的]
- //将ueditor的配置项以数组键值对的方式传入,具体查看ueditor.config.js
- //不要配置serverUrl(即使配置也会被覆盖)程序会自动处理后端url
- 'config'=>array(
- 'toolbars'=>array(array('fullscreen', 'source', '|')),//toolbars注意是嵌套两个数组
- 'lang'=>'zh-cn'
- ) //Vevb.com
- )
- );
按照上边的步奏,不出意外的话,编辑器肯定会显示在页面上。
问题:上传图片不能用会报,后端配置项没有正常加载,上传插件不能正常使用的错误。
解决方法:目录结构中有这个UeditorController.php文件,请将此文件放到你网站的controller目录下,因为上传图片最终会访问到此文件,我网站的访问路径是/admin/index.php?r=ueditor&action=config&&noCache=1464083990339,看到这个路径应该就明白了吧。
新闻热点
疑难解答