【军哥谈CI框架】之CI中集成百度UEditor

    Hello,各位亲,话说上一回,军哥带你们 用 JQuery写了一个全国城市级联菜单的例子 ,不知道亲们学会了多少,是否本身能够独立写出来了呢。

    军哥非常期待你们学有所获的,有不明白的地方随时留言吧。好了,接下来,今天军哥要带你们来一块儿来完成如何在CI框架中集成百度的UEditor编辑器。

    咱们先简单来了解一下为何选择百度UEditor编辑器? javascript

UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具备轻量,可定制,注重用户体验等特色,开源基于BSD协议,容许自由使用和修改代码,在众多的编辑器中仍是很出类拔萃的,目前百度编辑器也做为worderPress的插件替换了以前默认的编辑器,也足以看出UEditor的强大。
再来看一下效果图:




不赖吧,相信有淫已经等不急了吧!别急,咱们一步步来~~

1、官网上http://ueditor.baidu.com/website/ipanel/panel.html#载最新UEditorPHP + UTF-8完整源码包,解压到任意目录,解压后的源码目录结构以下所示:   
            _examples:编辑器完整版的示例页面
            dialogs:弹出对话框对应的资源和JS文件    
            themes:样式图片和样式文件
            php:涉及到服务器端操做的PHP文件    
            third-party:第三方插件
            editor_all.js_src目录下全部文件的打包文件    
            editor_all_min.jseditor_all.js文件的压缩版,建议在正式部署时才采用
            editor_config.js:编辑器的配置文件,建议和编辑器实例化页面置于同一目录 php

2、部署UEditorCI项目(CI_UETest)中的步骤


第一步:在项目的CI_UETest/public/scripts中创建一个用于存放UEditor相关资源和文件的目录,起名为ueditor。 


第二步:拷贝源码包中的php_srcdialogsthemesthird-partyeditor_config.jsCI_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>
第四步:而后在notice_edit.php文件中建立编辑器实例。具体代码示例以下:  
<script type="text/javascript">
      var ue = new UE.ui.Editor();
      ue.render('myEditor');  // myEditor为id值
</script>
最后一步: 在CI_UETest/public/scripts/ueditor/editor_config.js中查找URL变量配置编辑器在你项目中的路径。 
//强烈推荐以这种方式进行绝对路径配置 
URL= window.UEDITOR_HOME_URL || "/CI_UETest/public/scripts/ueditor/";  //第27行
3、其余
1在引用editor_config.js时,最好先于editor_all.js加载,不然特定状况下可能会出现报错。 

2编辑器中预置提示、问候等内容。 
editor_config.js文件中找到initialContent参数(第117,设置其值为须要的提示或者问候语便可,如initialContent:’你们好,我是军哥!lamp兄弟连,欢迎你!’。
相关文章
相关标签/搜索