How to use CKEditor in cake php 2.3

落爺英雄遲暮 提交于 2019-12-12 06:47:20

问题


I want to use CKEditor in cake php 2.3, trying a lot but not getting any solutions. basically I need image upload option in editor from local system.

How could I get success?


回答1:


After lots of research, finally i got the solution for implementing CKEditor with image upload option in cakephp 2.3

For image upload in CKEditor you have to use KCFinder please check the below link you can get the details there

http://cakephpclues.blogspot.in/2012/01/ckeditor-kcfinder-integration-with.html

Also the CKEditor have 3 package

  1. Basic Package
  2. Standard package
  3. Full Package

Also there is an option to customize the editor toolbar to down load CKEditor please visit - http://ckeditor.com/download




回答2:


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.

   <?php 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:

  <?php 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>



回答3:


Editor in website is so important to make the content more beautiful, so we will see how integration CKEditor and CKFinder with cakephp 2.x.

Creating editor helper: EditorHelper.php

<?php
class EditorHelper extends Helper
{
 function loadCK($id){
 $buff = "<script type=\"text/javascript\">
 //<![CDATA[
 var editor_$id = CKEDITOR.replace('$id', {customConfig : '/js/editor/config.js'});
 CKFinder.SetupCKEditor( editor_$id, '/js/ckfinder/' );
 //]]>
 </script>";
 return $buff;
 }
}
?>

Second we will call it in controller :

<?php
    public $helpers = array('Editor');
?>

Third we will creating the view : form.ctp

<script src="/js/editor/ckeditor.js" type="text/javascript"></script>
<script src="/js/ckfinder/ckfinder.js" type="text/javascript"></script>

<?php echo $this->Form->textarea('Item.content', array('size' => '32')); ?>
<?php echo $this->Editor->loadCK ('PagetextContent');  ?>

And After download ckeditor and ckfinder from source http://ckeditor.com and we will put them in /webroot/js/ folder.

That's it, Hope it's helpful.



来源:https://stackoverflow.com/questions/19424530/how-to-use-ckeditor-in-cake-php-2-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!