CI框架中集成CKEditor编辑器的教程_PHP教程
程序员文章站
2022-05-09 19:00:32
...
1、将fckeditor目录置入CI_PATH/system/plugins/
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 );
}
}
?>
$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 );
?>
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
复制代码 代码如下:
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
复制代码 代码如下:
$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 );
?>
上一篇: python中函数传参详解
下一篇: Python 字符串大小写转换的简单实例
推荐阅读
-
CI框架中集成CKEditor编辑器的教程
-
Laravel框架中扩展函数、扩展自定义类的方法,laravel框架_PHP教程
-
解析php框架codeigniter中如何使用框架的session_PHP教程
-
理解PHP中的MVC编程之MVC框架简介_PHP教程
-
CI中view的重写 代码_PHP教程
-
CI框架中zip类应用示例_PHP教程
-
详解PHP的Yii框架中组件行为的属性注入和方法注入,yii框架_PHP教程
-
深入解析PHP的Laravel框架中的event事件操作,laravelevent_PHP教程
-
php给编辑器中的图片添加域名_PHP教程
-
PHP的Yii框架中创建视图和渲染视图的方法详解,yii框架_PHP教程