content top
Integrating CKEditor in CakePHP

Integrating CKEditor in CakePHP

CKeditor/FCK Editor is  one of the world’s best WYSIWYG editor. CKEditor provides built-in file management functions.

(If you need a simple Rich Text Editor, I suggest you to use TinyMCE instead of  CKEditor)

If you want to integrate CKEditor to your CakePHP page, then follow the below steps.

Integrating CKEditor with CakePHP.

Step 1 :

Download CK Editor

http://ckeditor.com/download

Step 2 :

Unzip it and save the ckeditor directory in app\webroot\js folder.

Step 3 :

Open your controller class and Add ‘Javascript’ to $helpers array.

So your helper variable may look something like this.

var $helpers = array(’Html’, ‘Form’, ‘Javascript’);

Step 4 :

Include the ckeditor js file in your view.

<?php $javascript->link(’/js/ckeditor/ckeditor’, false);?>

Step 5 :

Add a text area to your view and add the  style class ‘ckeditor’ to text area.

echo $form->textarea(’txtEditor’, array(’class’=>’ckeditor’));

Done… Load the page…

Now you can see your FCK editor in your page.

Blog Widget by LinkWithin

6 Comments »

  1. avatar comment-top

    Many Thanks…….!

    comment-bottom
  2. avatar
    Willemsen Christophe Says:
    December 12th, 2009 at 9:34 pm
    comment-top

    Thanks a lot…

    comment-bottom
  3. avatar
    embeddedprogrammer Says:
    January 9th, 2010 at 11:09 pm
    comment-top

    Thanks very much. This is just what I needed.

    comment-bottom
  4. avatar comment-top

    Awesome, thanks!

    comment-bottom
  5. avatar comment-top

    I have inserted Ckeditor 3.x in my page and i submit my form data (along with the text area)to the controller. I am trying to save data to Mysql database but not able to save. I wonder if this is a correct way of doing it.

    Form name = Admin
    Field name = content
    Controller name = Admins
    Modelname = Admin

    $grn3 = $this->data['Admin']['content'] ;
    $this->Session->setFlash($grn3);
    $this->Admin->set($this->data ); //setting data to model
    $this->Admin->saveField(’content’, $grn3); //saving single

    field

    Setflash method flashes the data content, but save is not working. I am not sure if this is the way of saving text editor data to database. Please show me how to save editor data to

    datatbase.

    Thankx
    John M.

    comment-bottom
  6. avatar comment-top

    Hi John M,
    Adding a CKEditor to your page will not affect data saving in any way.
    Suppose you have a View page like this.
    echo $form->input(’title’);
    echo $form->input(’description’);

    Now only thing you are doing is to add a class to the existing input field.
    echo $form->input(’title’);
    echo $form->input(’description’, array(’class’=>’ckeditor’));

    So try to add a class ‘ckeditor’ to an existing field.

    comment-bottom

RSS feed for comments on this post. TrackBack URL

Leave a comment