用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6316|回复: 8
收起左侧

[插件 Plugin] ckeditor CI2.0 插件

  [复制链接]
发表于 2011-2-13 20:50:13 | 显示全部楼层 |阅读模式
本帖最后由 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 ckeditor_helper.zip (1.4 KB, 下载次数: 190) ,然后放置在application/helpers中
3.创建控制器test.php
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
HTML复制代码
<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方法来显示控制器中定义的编辑器。因此我感觉分离的更好一点。
发表于 2011-2-23 16:13:52 | 显示全部楼层
sofa
发表于 2011-3-9 15:53:31 | 显示全部楼层
留名学习
发表于 2011-3-9 17:57:15 | 显示全部楼层
做个记号
发表于 2011-5-5 10:43:32 | 显示全部楼层
mark mark mark
发表于 2011-7-25 14:18:27 | 显示全部楼层
不错,可以正常使用
发表于 2011-7-29 22:39:26 | 显示全部楼层
很不错,只是这个最新版本的编辑器怎么不能上传图片!
发表于 2011-7-30 10:59:21 | 显示全部楼层
问下楼主开启了图片上传 ,怎么配置文件上传的路径?我下的最新版本的!
发表于 2012-7-12 17:58:29 | 显示全部楼层
我想知道1.7的怎么弄的

本版积分规则