Integration of CKEditor editor in CI framework: tutorial _ php instance

Source: Internet
Author: User
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 );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.