咱们先简单来了解一下为何选择百度UEditor编辑器? javascript
UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具备轻量,可定制,注重用户体验等特色,开源基于BSD协议,容许自由使用和修改代码,在众多的编辑器中仍是很出类拔萃的,目前百度编辑器也做为worderPress的插件替换了以前默认的编辑器,也足以看出UEditor的强大。再来看一下效果图:
不赖吧,相信有淫已经等不急了吧!别急,咱们一步步来~~
1、官网上http://ueditor.baidu.com/website/ipanel/panel.html#下载最新UEditor的PHP + UTF-8版完整源码包,解压到任意目录,解压后的源码目录结构以下所示:
_examples:编辑器完整版的示例页面
dialogs:弹出对话框对应的资源和JS文件
themes:样式图片和样式文件
php:涉及到服务器端操做的PHP文件
third-party:第三方插件
editor_all.js:_src目录下全部文件的打包文件
editor_all_min.js:editor_all.js文件的压缩版,建议在正式部署时才采用
editor_config.js:编辑器的配置文件,建议和编辑器实例化页面置于同一目录 php
2、部署UEditor到CI项目(CI_UETest)中的步骤
第一步:在项目的CI_UETest/public/scripts中创建一个用于存放UEditor相关资源和文件的目录,起名为ueditor。
第二步:拷贝源码包中的php、_src、dialogs、themes、third-party和editor_config.js到CI_UETest/public/scripts/ueditor文夹中。
第三步:咱们以公告管理模块中的发布公告页面做为编辑器的实例化页面,用来展现UEditor的完整版效果。 css
一、控制器: html
if (!defined('BASEPATH')) exit('No direct script access allowed'); /** * @author JayJun * @copyright 2012.09.10 */ class notice extends CI_Controller { //构造函数 function __construct(){ parent::__construct(); $this->base_url = $this->config->item("base_url"); } //显示公告发布页面 function edit() { $data['base_url'] = $this->base_url; $this->load->helper('form'); //加载表单辅助函数 // 显示视图 $this->load->view('notice_edit', $data); } }二、视图:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>发布公告</title> <link rel="stylesheet" href="<?php echo $base_url; ?>/public/css/base.css" type="text/css" /> <link rel="stylesheet" href="<?php echo $base_url; ?>/bootstrap/css/bootstrap.min.css" type="text/css" /> <link rel="stylesheet" href="<?php echo $base_url; ?>/public/scripts/ueditor/themes/default/ueditor.css" type="text/css" /> <script type="text/javascript" src="<?php echo $base_url; ?>/public/scripts/ueditor/editor_config.js"></script> <script type="text/javascript" src="<?php echo $base_url; ?>/public/scripts/ueditor/editor_all.js"></script> </head> <body> <div class="w800 bc"> <h2>发布公告</h2> <table class="table table-condensed table-bordered mt10"> <?php echo form_open();?> <thead> <tr> <td colspan="2" class="fb"> <span class="icon-exclamation-sign"></span> 新发布的公告默认为不显示. </td> </tr> </thead> <tbody> <tr> <td width='15%' class="fb">公告标题:</td> <td><?php echo form_input('Title')?></td> </tr> <tr> <td class="fb">公告内容:</td> <td> <?php echo form_textarea('Content','','id="myEditor"'); ?> </td> </tr> <tr> <td class="fb">是否显示:</td> <td><?php echo form_checkbox("Nstatus") ;?></td> </tr> <tr> <td colspan='2' class="form-actions"> <?php echo form_submit("submit","提交","class='btn btn-primary'"); ?> <?php echo form_reset("reset","重置","class='btn'"); ?> </td> </tr> </tbody> <?php echo form_close(); ?> </table> </div> </body> </html>
<script type="text/javascript"> var ue = new UE.ui.Editor(); ue.render('myEditor'); // myEditor为id值 </script>
//强烈推荐以这种方式进行绝对路径配置 URL= window.UEDITOR_HOME_URL || "/CI_UETest/public/scripts/ueditor/"; //第27行3、其余