Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor in CodeIgniter

I wanna load CKEditor in CodeIgniter,I search a lot,but can't understand their way.

I placed ckeditor in application/plugins folder and now I wanna make editor ,so I do following in Controller Method.

include APPPATH.'plugins/ckeditor/ckeditor.php';
$CKEditor = new CKEditor();
$CKEditor->basePath = '/'.APPPATH.'plugins/ckeditor/';
$initialValue = '<p>This is some <strong>sample text</strong>.</p>';
echo $CKEditor->editor("editor1", $initialValue);

but it makes simple teaxaria only ,with

This is some sample text.

value. where is the problem and how should I solve it?

like image 847
Moein Hosseini Avatar asked Aug 05 '12 08:08

Moein Hosseini


People also ask

What is CKEditor used for?

CKEditor (formerly known as FCKeditor) is a WYSIWYG rich text editor which enables writing content directly inside of web pages or online applications. Its core code is written in JavaScript and it is developed by CKSource. CKEditor is available under open source and commercial licenses.

Is CKEditor a wysiwyg?

CKEditor is a WYSIWYG HTML editor that can fit a wide range of use cases: from Word-like documents with large toolbars to simple toolbars with a limited set of features used for emails or instant messaging. Get one complete software solution: rich text editor, file manager and collaboration features.


2 Answers

I use this steps to add ckeditor to my codeigniter apps:

1) Download these files:

  • This for Ckeditor: http://pastebin.com/fkK9e0RR
  • This for Ckfinder: http://pastebin.com/SvyypmX4

2) Copy the files you just downloaded into your Application/libraries folder

3) Download the ckeditor helper here: http://pastebin.com/Cd3GqYbx

4) Copy the last file in application/helper folder as ckeditor_helper.php

5) Download the CKeditor controller here: http://pastebin.com/UD0bB9ig

6) Copy the controller in your application/controllers folder as ckeditor.php

7) Download the main ckeditor project from the official site: http://ckeditor.com/download/

8) Copy the ckeditor folder you just download into your asset folder (if you want you can also download the ckfinder project and put it in the same folder)

9) Add these line of js to your view file (adjust the path):

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

10) In your controller add this php code and adjust the path:

$this->load->library('ckeditor');
$this->load->library('ckfinder');



$this->ckeditor->basePath = base_url().'asset/ckeditor/';
$this->ckeditor->config['toolbar'] = array(
                array( 'Source', '-', 'Bold', 'Italic', 'Underline', '-','Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo','-','NumberedList','BulletedList' )
                                                    );
$this->ckeditor->config['language'] = 'it';
$this->ckeditor->config['width'] = '730px';
$this->ckeditor->config['height'] = '300px';            

//Add Ckfinder to Ckeditor
$this->ckfinder->SetupCKEditor($this->ckeditor,'../../asset/ckfinder/'); 

11) In your view print the editor with:

echo $this->ckeditor->editor("textarea name","default textarea value");
like image 131
Christian Giupponi Avatar answered Sep 23 '22 04:09

Christian Giupponi


You could otherwise do this:

  1. copy the CKEditor files to a folder in your source's root eg ckeditor
  2. Include the CKEditor files in your view file

     <script src="<?php echo base_url(); ?>ckeditor/ckeditor.js"></script>
            <link rel="stylesheet" href="<?php base_url(); ?>style/format.css">
    
  3. finally your textarea in your html document

     <textarea cols="80" id="edi" name="editor1" rows="10">
                    <?php echo $page_content->message1; ?>
                                </textarea>
                                <script>
    
                                    CKEDITOR.replace('edi');
    
                         </script>    </body>   
    

This works great for me. Enjoy!

like image 43
user2143384 Avatar answered Sep 19 '22 04:09

user2143384