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

所属分类: 网络编程 / PHP编程 阅读数: 444
收藏 0 赞 0 分享

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

更多精彩内容其他人还在看

PHP 计算代码执行耗时的代码修正网上普遍错误

前几天测试 SQLite 插入大数据量的时候, 找了一些关于计算执行时间的代码, 发现网上普遍流传着这样一份代码
收藏 0 赞 0 分享

php中在PDO中使用事务(Transaction)

事务 (Transaction) 是操作数据库中很重要的一个功能, 它可以让你预定一条, 或者一系列 SQL 语句, 然后一起执行
收藏 0 赞 0 分享

centos 5.6 升级php到5.3的方法

centos 5.6的库,更新比比5.5及时多了,居然已经有 php 5.3.3 了
收藏 0 赞 0 分享

rrmdir php中递归删除目录及目录下的文件

php自带的rmdir,只能删除空目录,这个rrmdir就可以递归删除目录及目录下的所有文件,不过使用起来要小心哦,不要把所有文件都删了
收藏 0 赞 0 分享

Views rows style模板重写代码

重写rows style模板,可以控制整个VIEWS的输出布局,就像VIEWS是个选择器,布局任你编排
收藏 0 赞 0 分享

PHP中break及continue两个流程控制指令区别分析

php中常用的for与foreach循环中,经常遇到条件判断或中止循环的情况。而处理方式主要用到break及continue两个流程控制指令,现在说明主要区别
收藏 0 赞 0 分享

SWFUpload与CI不能正确上传识别文件MIME类型解决方法分享

问题:swfupload上传任何文件的mime类型均为application/octet-stream。
收藏 0 赞 0 分享

PHP session有效期session.gc_maxlifetime

PHP中的session有效期默认是1440秒(24分钟)【weiweiok 注:php5里默认的是180分】,也就是说,客户端超过24分钟没有刷新,当前session就会失效。很明显,这是不能满足需要的。
收藏 0 赞 0 分享

关于session在PHP5的配置文件中的详细设置参数说明

关于session在PHP5的配置文件中的详细设置参数说明,需要的朋友可以参考下。
收藏 0 赞 0 分享

PHP中的session永不过期的解决思路及实现方法分享

让PHP的session永不过期,你可能没有遇到这么郁闷的问题,但是我遇到过,很郁闷。
收藏 0 赞 0 分享
查看更多