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

来源:互联网 发布:jquery点击事件源码 编辑:程序博客网 时间:2024/06/02 04:15

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

作者: 字体:[增加 减小] 类型:转载 时间:2014-06-09
CKEditor是在很多开发过程中都会用到的一个富文本编辑器,那么如何在CI框架中使用它呢?这里介绍了在CI下使用CKEditor的方法,版本比较低,是在CI 1.7.3下使用fckeditor 2.6.6。供大家参考。
<iframe id="cproIframe_u1892994_2" marginheight="0" src="http://pos.baidu.com/acom?adn=3&amp;at=231&amp;aurl=&amp;cad=1&amp;ccd=24&amp;cec=gb2312&amp;cfv=16&amp;ch=0&amp;col=zh-cn&amp;conBW=0&amp;conOP=1&amp;cpa=1&amp;dai=2&amp;dis=0&amp;ltr=&amp;ltu=http%3A%2F%2Fwww.jb51.net%2Farticle%2F50840.htm&amp;lu_161=0&amp;lunum=6&amp;n=jb51_cpr&amp;pcs=1522x710&amp;pis=10000x10000&amp;ps=516x296&amp;psr=1536x864&amp;pss=1522x710&amp;qn=67110bc3b3c16440&amp;rad=&amp;rsi0=580&amp;rsi1=90&amp;rsi5=4&amp;rss0=%23FFFFFF&amp;rss1=%23F7FCFF&amp;rss2=%230000ff&amp;rss3=%23444444&amp;rss4=%23008000&amp;rss5=&amp;rss6=%23e10900&amp;rss7=&amp;scale=&amp;skin=tabcloud_skin_3&amp;stid=5&amp;td_id=1892994&amp;titFF=%E5%AE%8B%E4%BD%93&amp;titFS=12&amp;titTA=left&amp;tn=text_default_580_90&amp;tpr=1440659874652&amp;ts=1&amp;version=2.0&amp;xuanting=0&amp;dtm=BAIDU_DUP2_SETJSONADSLOT&amp;dc=2&amp;di=u1892994&amp;ti=CI%E6%A1%86%E6%9E%B6%E4%B8%AD%E9%9B%86%E6%88%90CKEditor%E7%BC%96%E8%BE%91%E5%99%A8%E7%9A%84%E6%95%99%E7%A8%8B_php%E5%AE%9E%E4%BE%8B_%E8%84%9A%E6%9C%AC%E4%B9%8B%E5%AE%B6&amp;tt=1440659874607.254.317.317" allowtransparency="true" marginwidth="0" scrolling="no" align="center,center" frameborder="0" height="90" width="580"></iframe>

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 );
?>


0 0
原创粉丝点击