xueliang813 发表于 2011-2-13 20:50:13

ckeditor CI2.0 插件

本帖最后由 xueliang813 于 2011-2-13 22:10 编辑

CI现在已经是2.0了,在1.7版本的时候,采用论坛当中一兄弟的FCKeditor类库,在次对那位兄弟表示感谢。最近打算升级到2.0。不打算用类库的形式来添加编辑器了,于是找了一篇国外的为CI添加CKeditor的文章,现在整理一下贴出来,抛砖引玉,大家看看有没有什么更好的方式没有。

1.下载最新稳定的CKeditor http://ckeditor.com/download,放在程序目录中的任意位置(可以放在任意位置,在控制器中配置的时候会用到这个路径),我的方式是放在程序根目录下面的public/ckeditor
2.下载附件中的ckeditor_helper.php,然后放置在application/helpers中
3.创建控制器test.php


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller{
    var $data;
    function__construct() {
      parent::__construct();
      $this->load->helper('ckeditor');//加载helper
      $this->data['ckeditor'] = array(
                'id'         =>         'content',//模板中textareaID
                'path'        =>      'public/ckeditor',//ckeditor目录

                //Optionnal values
                'config' => array(
                        'toolbar'         =>         "Full",
                        'width'         =>         "850px",       
                        'height'         =>         '100px',       
                ),

                //Replacing styles from the "Styles tool"
                'styles' => array(
                        //Creating a new style named "style 1"
                        'style 1' => array (
                              'name'                 =>         'Blue Title',
                              'element'         =>         'h2',
                              'styles' => array(
                                        'color'         =>         'Blue',
                                        'font-weight'         =>         'bold'
                              )
                        ),

                        //Creating a new style named "style 2"
                        'style 2' => array (
                              'name'         =>         'Red Title',
                              'element'         =>         'h2',
                              'styles' => array(
                                        'color'                 =>         'Red',
                                        'font-weight'                 =>         'bold',
                                        'text-decoration'        =>         'underline'
                              )
                        )
                )
      );
      $this->data['ckeditor_2'] = array(

                //ID of the textarea that will be replaced
                'id'         =>         'content_2',
                'path'        =>        'public/ckeditor',

                //Optionnal values
                'config' => array(
                        'width'         =>         "550px",        //Setting a custom width
                        'height'         =>         '100px',        //Setting a custom height
                        'toolbar'         =>         array(        //Setting a custom toolbar
                              array('Bold', 'Italic'),
                              array('Underline', 'Strike', 'FontSize'),
                              array('Smiley'),
                              '/'
                        )
                ),

                //Replacing styles from the "Styles tool"
                'styles' => array(

                        //Creating a new style named "style 1"
                        'style 3' => array (
                              'name'                 =>         'Green Title',
                              'element'         =>         'h3',
                              'styles' => array(
                                        'color'         =>         'Green',
                                        'font-weight'         =>         'bold'
                              )
                        )

                )
      );
    }
   
    function index(){
      $this->load->view('test', $this->data);
    }

}

4.创建视图文件test.php
<body>
fckeditor here <br />
<textarea name="content" id="content" ><p>Example data</p></textarea>
<?php echo display_ckeditor($ckeditor); ?>
<textarea name="content_2" id="content_2" ><p>Example data</p></textarea>
<?php echo display_ckeditor($ckeditor_2); ?>
</textarea>
</body>


上面在控制器中定义了两种不同功能的CKeditor,一个功能多点,一个只有最基本的加粗表情等。
然后在视图文件中通过display_ckeditor方法来显示控制器中定义的编辑器。因此我感觉分离的更好一点。

jiekii 发表于 2011-2-23 16:13:52

sofa:victory:

hmily36 发表于 2011-3-9 15:53:31

留名学习

davidx 发表于 2011-3-9 17:57:15

做个记号

xgamers 发表于 2011-5-5 10:43:32

mark mark mark

WillLe 发表于 2011-7-25 14:18:27

不错,可以正常使用:D

Selenium_Wei 发表于 2011-7-29 22:39:26

很不错,只是这个最新版本的编辑器怎么不能上传图片!:'(

Selenium_Wei 发表于 2011-7-30 10:59:21

问下楼主开启了图片上传 ,怎么配置文件上传的路径?我下的最新版本的!

zwm 发表于 2012-7-12 17:58:29

我想知道1.7的怎么弄的
页: [1]
查看完整版本: ckeditor CI2.0 插件