CKEditor 3.x - New FCKEditor Version

This article is also available in the following languages:
By Valkum
Now FCKEditor is called CKEditor. And here is an running Version of CKEditor and CakePHP.

CKEditor is an WYSIWYG Javascript Editor.



To Enable CKEditor functionality in your CakePHP version,
download CKEditor from CKEditors Downloadpage -> http://ckeditor.com/download
Extract the downloaded archive to /app/webroot/js

so that you have the following tree structure

+-/app/webroot/js
+---/ckeditor
+------/images
+------/lang
+------/plugins
+------/skins
+------/themes


Helper Class:

<?php 
<?php
class FckHelper extends Helper {

    var 
$helpers = Array('Html''Javascript');

    function 
load($id) {
        
$did '';
        foreach (
explode('.'$id) as $v) {
            
$did .= ucfirst($v);
        } 

        
$code "CKEDITOR.replace( '".$did."' );";
        return 
$this->Javascript->codeBlock($code); 
    }
}
?>


To call CKEditor in a View put this into your *.ctp

View Template:


<?php
echo $javascript->link('ckeditor/ckeditor'NULLfalse);
?>
and

View Template:


<?php
echo $fck->load('Model.field');
?>


An example is:

View Template:


<?php
    
echo $javascript->link('ckeditor/ckeditor'NULLfalse);

    echo 
$form->create('News', array('action' => 'edit'));
    echo 
$form->input('title');
    echo 
$form->input('body', array('cols' => '60''rows' => '3'));
    echo 
$fck->load('News.body');
    echo 
$form->input('id', array('type'=>'hidden')); 
    echo 
$form->end('Save Post');
?>


Reqs:
Javascript helper must be included. ($helpers)

Comments

  • Posted 08/03/11 02:41:02 PM
    Hi all!!
    My english level is not good, i hope you know what i need to say.
    My boss asked me create ckeditor plugin to reuse it in other application.
    and he wants everything about it is contented in app/plugins/flexicore
    But the ckeditor source (images,js,css) should storage in webroot/js.
    when i try to use it by storage in app/plugins/flexicore/webroot/js and the cksource.php in app\plugins\flexicore\views\helpers.
    the browser return error like: require_once(C:\AMP\apache\htdocs\Flexicore\app\webroot\\js\ckeditor\ckeditor.php
    Now how can i fix that error?
    please helpme. thank all
  • Posted 07/14/10 03:25:00 AM
    Hi, I'm not sure what exactly you guys are trying to do with the use of the helper.
    Isn't CKEditor supposed to work with something like this:

    $javascript->link('ckeditor/ckeditor', false);

    form->create blah

    echo $form->textarea('txt',array('label' => false,'cols'=>'50','rows'=>'3','div'=>false,'class'=>'ckeditor'));

    form->end blah

    it seems as it's just complicating things to me.
    Could someone explain what that helper is actually doing???
    • Posted 07/14/10 08:07:18 AM
      @Atsushi - I want to implement ckfinder functionality in ckeditor and hence tried this code but didn't work. Have you tried ckfinder (for image upload) with ckeditor in cakephp?
      • Posted 07/15/10 03:31:24 AM
        @Atsushi - I want to implement ckfinder functionality in ckeditor and hence tried this code but didn't work. Have you tried ckfinder (for image upload) with ckeditor in cakephp?
        @Usman -
        No, I have not yet tried to incorporate ckfinder to my cake project.
        Currently for image upload, I have another window opened to browse image files uploaded on the server.
        Isnt your code sample missing < ? p h p ? > on the last line around "echo $ckfinderPath"?
        • Posted 07/22/10 06:35:12 PM
          @Atsushi - I want to implement ckfinder functionality in ckeditor and hence tried this code but didn't work. Have you tried ckfinder (for image upload) with ckeditor in cakephp?
          @Usman -
          No, I have not yet tried to incorporate ckfinder to my cake project.
          Currently for image upload, I have another window opened to browse image files uploaded on the server.
          Isnt your code sample missing < ? p h p ? > on the last line around "echo $ckfinderPath"?

          @Atsushi Yes the php tags are missing as this forum seems to be stripping them. What are you using for image upload?
  • Posted 05/20/10 12:35:28 PM
    This is the code i am using similar to the code @long posted, it shows editor but does not show browse server button when uploading image:

    class AppController extends Controller {
    var $components = array('Session');
    var $helpers = array('Ajax', 'Javascript', 'Time', 'Form', 'Html', 'Session');
    function beforeFilter() {
    $ckeditorClass = 'ckeditor';
    $this->set('ckeditorClass', $ckeditorClass);
    $ckfinderPath = $this->webroot.'js/ckfinder/';
    $this->set('ckfinderPath', $ckfinderPath);
    }
    }

    In the view:
    echo $form->textarea('content', array('class'=>$ckeditorClass));
    ?> var editor = CKEDITOR.replace('NewsFeature.content');
    CKFinder.SetupCKEditor( editor, ' echo $ckfinderPath ') ;



    Any help will be appreciated.

    Thanks,
    Usman
  • Posted 05/15/10 10:20:35 PM
    AppController:

    class AppController extends Controller {
        var $components = array('Menu','Session');
        var $helpers = array('Ajax', 'Javascript', 'Time', 'Form', 'Html', 'Session');
        function beforeFilter() {
            $ckeditorClass = 'ckeditor';
            $this->set('ckeditorClass', $ckeditorClass);
            $ckfinderPath = $this->webroot.'js/ckfinder/';
            $this->set('ckfinderPath', $ckfinderPath);
        }
    }
    ----------------------------------------------------------
    view:

    <?php 
    echo $javascript->link('ckeditor/ckeditor.js');
    echo 
    $javascript->link('ckfinder/ckfinder.js'); 
    ?>
    <script type="text/javascript">
    var editor = CKEDITOR.replace( 'BlogDesc' ); //html tag #ID
    CKFinder.SetupCKEditor( editor, '<?php echo $ckfinderPath ?>') ;
    </script>
  • Posted 04/28/10 09:59:32 AM
    Hi,

    Great article - how can i include the ckfinder functionality in the code mentioned in the article?

    Thanks,
    Usman
  • Posted 03/23/10 02:27:57 AM

    Helper Class:

    <?php 
    class FckHelper extends Helper {

        var 
    $helpers = Array('Html''Javascript');

        function 
    load($id,$options_=array()) {
            
    $options = array(
                        
    'language'=>'it',
                        
    'uiColor'=>'#7E9DCC',
                        
    'toolbar'=>'Full',
                        );
            if(!empty(
    $options_)) array_merge($options,$options_);
            
    $did '';
            foreach (
    explode('.'$id) as $v) {
                
    $did .= Inflector::camelize($v);
            }
            
    $did Inflector::humanize($did);
            
            
    $code " if (CKEDITOR.instances['".$did."']) {
                        CKEDITOR.remove(CKEDITOR.instances['"
    .$did."']);
                        cckeditor"
    .$did.".destroy();
                        cckeditor"
    .$did." = null;
                     }\n"
    ;
            
    $code .= " cckeditor".$did." = CKEDITOR.replace( '".$did."',".$this->Javascript->object($options).");\n";
            return 
    $this->Javascript->codeBlock($code); 
        }
    }
    ?>

    This is my Helkper, I used it in many website attrezzatura subacquea, immersioni, siti web pronti, investimenti immobiliari
  • Posted 03/03/10 09:26:15 PM
    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

    mycontroller code:
    $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.
  • Posted 01/18/10 08:54:24 PM
    There are some alternatives to CkFinder for people who want something more open / free.

    eg, this one:
    http://labs.corefive.com/2009/10/30/an-open-file-manager-for-ckeditor-3-0/
    I installed it into my cakeapp like this:
    http://www.asecondsystem.com/2010/01/19/integrating-a-file-browser-into-ckeditor-cakephp/#more-327
  • Posted 11/11/09 06:08:47 PM
    CkEditor will auto replace, meaning all you have to do is include it, and add a class to your inputs.

    Whats the benefit of the above code? Iv'e plugged this before, but to show what i'm on about:

    http://www.asecondsystem.com/2009/09/14/integrating-ck-editor-with-cakephp/
    I'm planning to just have a file browser (not uploader) for the images when thats required, so users can select from the images in the sites media folder, which i populate with uploadify elsewhere. (but thats anouther story).

    Will
  • Posted 11/09/09 11:01:42 PM
    Thanks for the tutorial! I had problems with authentication on CKFinder actually. So I wrote a tutorial on BeamStyle on setting up CKFinder on CakePHP with SESSION AUTHENTICATION as well. Perhaps you guys can take a look on that?

    How to integrate CKEditor + CKFinder with Session Authorization into CakePHP --> http://blog.beamstyle.com.hk/?p=170
  • Posted 11/09/09 01:49:48 AM
    @Valkum, thanks for the article!

    However, you could at least have mentioned CKFinder, since the file manager is not a part of the core editor anymore.
    Also, CKFinder now supports some basic authorization, plus authentication through access to the current session which makes it possible to prevent file uploads by unauthenticated users
    • Posted 11/09/09 04:30:40 AM
      you could at least have mentioned CKFinder, since the file manager is not a part of the core editor anymore. Most of the time, it's not needed, is it?
      It was a very good idea to separate it from the rest of the project. :)

Comments are closed for articles over a year old