我从山中来

我是网络一看客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

在yii framework中集成ckeditor与ckfinder

Posted on 2010-12-08 19:58  我从山中来  阅读(1793)  评论(0编辑  收藏  举报

首先请参看yii的这个扩展:

ckeditor-integration

这个扩展整合了ckeditor,但美中不足的是没集成ckfinder,于是对其手工修改,已能正常使用

我的主要路径是这样的

MyApp

----ckeditor

----ckfinder

----protected

......略

 

上边的扩展文件就是两个,

protected/extensions/ckeditor/CKEditorWidget.php

protected/extensions/ckeditor/views/CKEditorView.php

 

下边就是我对这两个文件修改后的样子

CKEditorWidget.php

 

代码
class CKEditorWidget extends CInputWidget
{

public $ckEditor;
public $ckFinder;
public $ckBasePath;
public $defaultValue;
public $config;

public function run()
{
if(!isset($this->model)){
throw new CHttpException(500,'"model" 必需设置!');
}
if(!isset($this->attribute)){
throw new CHttpException(500,'"attribute" 必须设置!');
}
if(!isset($this->ckFinder)){
$this->ckFinder = Yii::app()->basePath."/../ckfinder/ckfinder.php";
}
if(!isset($this->ckEditor)){
$this->ckEditor = Yii::app()->basePath."/../ckeditor/ckeditor.php";
}
if(!isset($this->ckBasePath)){
$this->ckBasePath = Yii::app()->baseUrl."/ckeditor/";
}
if(!isset($this->defaultValue)){
$this->defaultValue = "";
}

$controller=$this->controller;
$action=$controller->action;
$this->render('CKEditorView',array(
"ckFinder"=>$this->ckFinder,
"ckEditor"=>$this->ckEditor,
"ckBasePath"=>$this->ckBasePath,
"model"=>$this->model,
"attribute"=>$this->attribute,
"defaultValue"=>$this->defaultValue,
"config"=>$this->config,
));
}
}

 

 

CKEditorView.php

 

代码
require_once($ckEditor);
require_once($ckFinder);

$oCKeditor = new CKeditor(get_class($model).'['.$attribute.']');
$oCKeditor->basePath = $ckBasePath;

if(isset($config) && is_array($config)){
foreach($config as $key=>$value){
$oCKeditor->config[$key] = $value;
}
}

CKFinder
::SetupCKEditor($oCKeditor, Yii::app()->baseUrl . '/ckfinder/');
$oCKeditor->editor(get_class($model).'['.$attribute.']',$defaultValue);

 

 

这样,就可以使用最新的ckeditor与ckfinder了,剩下的就是修改ckeditor与ckfinder的配置以适合要求,例如ckfinder上传中文文件时文件名问题的修改等等,网上有许多这方面的文章