CKEditor is a rich text editor used in many development processes. How to use it in the CI framework? This section describes how to use CKEditor in CI. The version is relatively low and fckeditor2.6.6 is used in CI1.7.3. For your reference. 1. Put the fckeditor Directory into CI_PATH/system/plugins/
2. Add the following to CI_PATH/system/application/config. php:
$ Config ['fckeditor _ basepath'] = "/system/plugins/fckeditor /";
$ Config ['fckeditor _ toolbarset_default '] = 'default ';
3. Create helper and create form_helper.php in/system/application/helpers
The Code is as follows:
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. Use fckeditor in the project
The Code is as follows:
$ This-> load-> helper ('form _ helper ');
$ Data = array (
'Name' => 'newscontent ',
'Id' => 'newscontent ',
// 'Toolbarset' => 'advanced ',
'Basepath' => $ this-> config-> item ('fckeditor _ basepath '),
'Width' => '123 ',
'Height' => '123'
);
Echo form_fckeditor ($ data );
?>