|
原文地址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 ); 复制代码
测试成功。 |
|