codeigniter 整合(集成) ckeditor
本帖最后由 Antelope 于 2012-10-17 15:36 编辑懒得打字 ^_^
欢迎到我 Blog 坐坐.http://kingplesk.org
教程地址: http://kingplesk.org/2012/10/codeigniter-2-1-0-%E6%95%B4%E5%90%88%E9%9B%86%E6%88%90-ckeditor/
环境:codeigniter 2.1.0
php 5.3
CKEditor 3.6.5项目目录ci/———-application——————libraries/————————–editor.php 新建文件文件源码请看下面 code 1.1————————–ckeditor/ 复制 js/ckeditor/ckeditor_php5.php 文件到这个目录下,重命名为: ckeditor.php————————————-ckeditor.php———-js/——————-ckeditor/ 下载ckeditor放在此目录———system———uploads
editor.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Editor {
/*
Global object $CI
*/
private $CI;
public function __construct(){
$this->CI = & get_instance();
$this->CI->load->library('ckeditor');
$this->CI->ckeditor->basePath = base_url().'js/ckeditor/';
}
public function generate($name = 'myeditor',$value = '',$config = array(), $events = array()){
return $this->CI->ckeditor->editor($name, $value, $config, $events);
}
public function config($key , $value = ''){
if(empty($key)){
show_error(__CLASS__.'=>'.__FUNCTION__.' 参数 $key 不能为空');
}
$this->CI->ckeditor->config[$key] = $value;
return $this;
}
public function resize($width,$height){
$this->CI->ckeditor->config['width'] = $width;
$this->CI->ckeditor->config['height'] = $height;
return $this;
}
/**
* getCKEditor 返回 class CKEditor
**/
public function getCKEditor(){
return $this->CI->ckeditor;
}
}
code 1.2 调用例子
public function ckeditor(){
$this->load->library('editor');
//修改toolbar
$this->editor->config('toolbar',array(
array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
array( 'Image', 'Link', 'Unlink', 'Anchor' )
));
//修改宽高
$this->editor->config('width','600px')->config('height','350px');
//修改宽高
$this->editor->resize(/*宽*/'600px',/*高*/'350px');
//输出editor
echo $this->editor->generate(/*textarea name*/'editor_name','初始化数据');
echo $this->editor->resize(/*宽*/'600px',/*高*/'350px')->generate(/*textarea name*/'editor_name','初始化数据');
}
页:
[1]