用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6759|回复: 6
收起左侧

[插件 Plugin] CodeIgniter加入插件FCKeditor

[复制链接]
发表于 2009-1-24 16:10:42 | 显示全部楼层 |阅读模式
原文地址http://codeigniter.com/forums/viewthread/59265/

我使用的是FCKeditor_2.6.3 ,CodeIgniter_1.7.0
我自己的理解如下:(呵呵,翻译的不一定好。)

Step 1:
下载并加压缩FCKeditor文件到你选择的目录,建议选择 /system/plugins/fckeditor/ 或 /system/application/plugins/fckeditor/,我选择的是外部的plugins。

Step 2:
加入下面 FCKEditor 的设置到 system/application/config/config.php :
PHP复制代码
/*
|--------------------------------------------------------------------------
| FCKEditor Basepath
|--------------------------------------------------------------------------
|
| The path from your site's root in which the fckeditor folder is. Note
| this is from the site's root, not the file system root. Also note the
| required slashes at start and finish.
|
|    e.g. /fckeditor/ or /system/plugins/fckeditor/  etc...
|
*/

$config['fckeditor_basepath']    = "/system/plugins/fckeditor/";
 
/*
|--------------------------------------------------------------------------
| FCKEditor Toolbar Set Default
|--------------------------------------------------------------------------
|
| The default Toolbar set to be used for FCKEditor across your site. Leave
| as empty string or comment out if your happy enough with the standard
| default.
|
*/

$config['fckeditor_toolbarset_default'] = 'Default';
复制代码


Step 3:
最后加入一个新的helper类form_helper.php到/system/application/helpers/下,代码如下:
PHP复制代码
<!--****** FILE /system/application/helpers/form_helper.php code ********-->
 
<?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 );
    }
}
 
?>
复制代码


实例如下:
PHP复制代码
$this->load->helper('form_helper');
$data = array(
              'name'        => 'textareaName2',
              'id'          => 'textareaName2',
               // 'toolbarset'  => 'Advanced',
              'basepath'    => '/fckeditor/',
              'width'       => '100%',
              'height'      => '200'
    );
 
echo form_fckeditor( $data );
复制代码


测试成功。
发表于 2009-1-24 21:58:31 | 显示全部楼层
晕,竟然放这里了,楼主英文不错
发表于 2009-1-26 19:10:19 | 显示全部楼层
已经帮楼主转移了,呵呵
发表于 2009-6-17 11:25:12 | 显示全部楼层
调试100次,。 102次失败!!!!!
发表于 2009-7-10 14:07:55 | 显示全部楼层
你失败次数真高!
发表于 2011-1-13 11:00:19 | 显示全部楼层
不错啊
呵呵
发表于 2012-3-26 21:08:38 | 显示全部楼层
怎么我的ci文件没有plugin这个文件夹呢

本版积分规则