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 );
测试成功。 晕,竟然放这里了,楼主英文不错 已经帮楼主转移了,呵呵 调试100次,。 102次失败!!!!! 你失败次数真高! 不错啊
呵呵 怎么我的ci文件没有plugin这个文件夹呢
页:
[1]