CI框架中集成CKEditor编辑器的教程

 更新时间:2014年06月09日 16:27:22   作者:  
CKEditor是在很多开发过程中都会用到的一个富文本编辑器,那么如何在CI框架中使用它呢?这里介绍了在CI下使用CKEditor的方法,版本比较低,是在CI 1.7.3下使用fckeditor 2.6.6。供大家参考。

1、将fckeditor目录置入CI_PATH/system/plugins/

2、在CI_PATH/system/application/config/config.php中加入:

$config['fckeditor_basepath'] = "/system/plugins/fckeditor/";
$config['fckeditor_toolbarset_default'] = 'Default';

3、创建helper,在/system/application/helpers新建form_helper.php

复制代码 代码如下:

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once( BASEPATH . '/helpers/form_helper'.EXT);
function form_fckeditor($data = '', $value = '', $extra = '')
{
     $CI =& get_instance();
    $fckeditor_basepath = $CI->config->item('fckeditor_basepath');
     require_once( $_SERVER["DOCUMENT_ROOT"] . $fckeditor_basepath. 'fckeditor.php' );
    $instanceName = ( is_array($data) && isset($data['name'])   ) ? $data['name'] : $data;
    $fckeditor = new FCKeditor($instanceName);
     if( $fckeditor->IsCompatible() )
    {
         $fckeditor->Value = html_entity_decode($value);
        $fckeditor->BasePath = $fckeditor_basepath;
         if( $fckeditor_toolbarset = $CI->config->item('fckeditor_toolbarset_default'))
                $fckeditor->ToolbarSet = $fckeditor_toolbarset;
         if( is_array($data) )
        {
            if( isset($data['value']) )
                $fckeditor->Value = html_entity_decode($data['value']);
             if( isset($data['basepath']) )
                $fckeditor->BasePath = $data['basepath'];
             if( isset($data['toolbarset']) )
                $fckeditor->ToolbarSet = $data['toolbarset'];
             if( isset($data['width']) )
                $fckeditor->Width = $data['width'];
             if( isset($data['height']) )
                $fckeditor->Height = $data['height'];
        }
        return $fckeditor->CreateHtml();
    }
    else
    {
        return form_textarea( $data, $value, $extra );
    }
}
?>

4、在项目中使用fckeditor

复制代码 代码如下:

<?php
$this->load->helper('form_helper');
$data = array(
    'name'        => 'newsContent',
    'id'          => 'newsContent',
    //'toolbarset'  => 'Advanced',
    'basepath'    => $this->config->item('fckeditor_basepath'),
    'width'       => '80%',
    'height'      => '200'
);
echo form_fckeditor( $data );
?>

相关文章

  • Zend Framework教程之Zend_Controller_Plugin插件用法详解

    Zend Framework教程之Zend_Controller_Plugin插件用法详解

    这篇文章主要介绍了Zend Framework教程之Zend_Controller_Plugin插件用法,结合实例形式详细分析了Zend_Controller_Plugin插件的原理,使用方法与相关注意事项,需要的朋友可以参考下
    2016-03-03
  • ThinkPHP整合百度Ueditor图文教程

    ThinkPHP整合百度Ueditor图文教程

    这篇文章主要介绍了ThinkPHP整合百度Ueditor的方法,图文并茂,非常的详细,希望对大家能有所帮助
    2014-10-10
  • 用php实现分页效果的示例代码

    用php实现分页效果的示例代码

    分页效果在网页中是常见的,可是怎样才能实现分页呢,今天做了两种方法来实现一下分页的效果,本文通过实例图文相结合给大家介绍的非常详细,需要的朋友参考下吧
    2020-12-12
  • PHP开发APP端微信支付功能

    PHP开发APP端微信支付功能

    这篇文章主要为大家详细介绍了PHP开发APP端微信支付的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-02-02
  • 基于jQueryUI和Corethink实现百度的搜索提示功能

    基于jQueryUI和Corethink实现百度的搜索提示功能

    这篇文章主要介绍了基于jQueryUI和Corethink实现百度的搜索提示功能,这里是以corethink模块的形式,只需要安装上访问index.php?s=/test/index 就可以了,需要的朋友可以参考下
    2016-11-11
  • Laravel框架学习笔记(一)环境搭建

    Laravel框架学习笔记(一)环境搭建

    本文主要是把自己学习Laravel框架中的经验写下来。这是本系列的第一篇,工欲善其事必先利其器,先把环境搭建好吧,之前也没写过什么文章,可能文章结构比较混乱,想到那写到哪。
    2014-10-10
  • laravel框架中间件 except 和 only 的用法示例

    laravel框架中间件 except 和 only 的用法示例

    这篇文章主要介绍了laravel框架中间件 except 和 only 的用法,简单说明了中间件 except 和 only的功能,并结合实例形式分析了laravel框架中间件 except 和 only 相关使用技巧,需要的朋友可以参考下
    2019-07-07
  • 使用php实现从身份证中提取生日

    使用php实现从身份证中提取生日

    本文给大家分享的是一则使用php实现的从身份证中提取出生日期的函数,非常的简单,有需要的小伙伴可以参考下
    2016-05-05
  • php加密解密实用类分享

    php加密解密实用类分享

    加密和解密是一项常规任务,这里介绍一个加解密类。如果你想在用户忘记密码时为他或她找回原来的密码,那么这个类是个好用的工具
    2014-01-01
  • 详解php用curl调用接口方法,get和post两种方式

    详解php用curl调用接口方法,get和post两种方式

    本篇文章主要介绍了详解php用curl调用接口方法,get和post两种方式,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-01-01

最新评论