Nov 25, 2011

Add fck editor in cakephp


Installation
1) Copy fckeditor folder to app/webroot/js/
2) Copy fckeditor.php, fckeditor_php4.php, fckeditor_php5.php to app/vendors/

Setup
Create a file in helpers called fck.php in view

<?php
App::import('Vendor', 'fckeditor');

class FckHelper extends AppHelper {

    /**
    * creates an fckeditor textarea
    *
    * @param array $namepair - used to build textarea name for views, array('Model', 'fieldname')
    * @param stirng $basepath - base path of project/system
    * @param string $content
    */
    function fckeditor($namepair = array(), $basepath = '', $content = ''){
        $editor_name = 'data';
        foreach ($namepair as $name){
            $editor_name .= "[" . $name . "]";
        }

        $oFCKeditor = new FCKeditor($editor_name) ;
        $oFCKeditor->BasePath = $basepath . '/js/fckeditor/' ;
        $oFCKeditor->Height="400px";
        $oFCKeditor->Value = $content ;
        $oFCKeditor->Create() ;
    }
}

?>
Usage

1) Add the fck helper to your controller

var $helpers = array('Html','Form','Javascript','Ajax','Fck','Time'); 

2) Use the following line in your views to display the fckeditor

echo $fck->fckeditor(array('Model', 'field'), $html->base, $yourContentVariable); 
Example

<?php echo $fck->fckeditor(array('Page','static_page_description'), $html->base,$this->data['Page']['static_page_description']);?>

*if any type of help is needed regarding prog or concept contact me on dadhich.priyank@gmail.com

No comments:

Post a Comment