Sunday, April 14, 2013
Integrating CKEditor with CakePHP
CKEditor is the web text editor used in web applications to convert your textarea to Rich TextArea.
Here we explain how to integrate CakePHP 2.x with CKEditor (version 4.1)
Download CKEditor and extract the files to app/webroot/js/ckeditor
Now in your ctp file add the below code so that the ckeditor.js file will be integrated in the head part of the page.
Note: in Layouts/default.ctp confirm that below code is placed in the head part
Now add the class to the form element to which you want to apply the CKEditor characteristics:
Now run your file.. Its DONE..!
In-order to change the other properties of the CKEditor like width, height and toolbar settings add the code in you ctp file. (U can paste it at the end of the ctp file)
Hope you got it. Thank you.
Here we explain how to integrate CakePHP 2.x with CKEditor (version 4.1)
Download CKEditor and extract the files to app/webroot/js/ckeditor
Now in your ctp file add the below code so that the ckeditor.js file will be integrated in the head part of the page.
echo $this->Html->script('ckeditor/ckeditor', array('inline' => false));
Note: in Layouts/default.ctp confirm that below code is placed in the head part
<?php echo $scripts_for_layout; ?>
Now add the class to the form element to which you want to apply the CKEditor characteristics:
echo $this->Form->textarea('myelement', array('class'=>'ckeditor'));
Now run your file.. Its DONE..!
In-order to change the other properties of the CKEditor like width, height and toolbar settings add the code in you ctp file. (U can paste it at the end of the ctp file)
<script type="text/javascript">
CKEDITOR.replace( 'textarea_id', {
toolbar: [[ 'Bold', 'Italic','Underline','Subscript','Superscript'],],
width: '700',
height: '100',
});
</script>
Hope you got it. Thank you.
Subscribe to:
Post Comments (Atom)
I can not insert data from ckeditor into database...
ReplyDeletecan you tell me how to do that ....
I didn't do anything special for that.
Deleteecho $this->Form->textarea('myelement', array('class'=>'ckeditor'));
Check that "myelement" and the fieldname in the database matches..
good
ReplyDeleteThis is SO WRONG.
ReplyDeleteYou DO NOT call the script file BEFORE head.
Implement this under before < / head >
echo $this->Html->script('ckeditor/ckeditor', array('inline' => false)); Should go under your layouts.
Hello friend, its not wrong.
DeleteU can call any script from CTP file. When the page is rendered it will automatically be included in the head section (provided that in the layout within the head section u have added "echo $scripts_for_layout;").
In this way we can avoid loading the js files for the pages which doesn't needs it.
is it working for anyone of you?
ReplyDeletei am getting error:
ReplyDeleteNotice (8): Undefined variable: scripts_for_layout [APP/Template/Layout/default.ctp, line 21]
Note: in Layouts/default.ctp confirm that below code is placed in the head part
Deletehi bro,how to get plain text
ReplyDelete