teng0210 发表于 2009-1-24 16:10:42

CodeIgniter加入插件FCKeditor

原文地址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 :
/*
|--------------------------------------------------------------------------
| 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/下,代码如下:
<!--****** FILE /system/application/helpers/form_helper.php code ********-->

<?phpif (!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 );
    }
}

?>

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

echo form_fckeditor( $data );

测试成功。

sam 发表于 2009-1-24 21:58:31

晕,竟然放这里了,楼主英文不错

Hex 发表于 2009-1-26 19:10:19

已经帮楼主转移了,呵呵

huapiaoxiang 发表于 2009-6-17 11:25:12

调试100次,。 102次失败!!!!!

echorenyuan 发表于 2009-7-10 14:07:55

你失败次数真高!

liaomars 发表于 2011-1-13 11:00:19

不错啊
呵呵

ocean_deep 发表于 2012-3-26 21:08:38

怎么我的ci文件没有plugin这个文件夹呢
页: [1]
查看完整版本: CodeIgniter加入插件FCKeditor