最近由于项目需要,我尝试把fckeditor集成到zend framework中去。相对于常规的集成方法,ZF中要麻烦一点,在次我们要做的是把Fckeditor写成一个Zend Framework 插件形式.,这样就可以让整个站点调用到FCK,这样无论是前台和后台都行..

1、下载最新的fckeditor 编辑器。
2、php结合zf环境是搭建完好且能正常运行。

总共步骤有5步。

第一步:新建Fckeditor.php类,即是以Fckeditor下的fckeditor_php5.php为基础的。

第二步:把fckeditor与zf整合

第三步:在zf控制层(controller)调用fckeditor插件

第四步:在视图中显示Fckeditor编辑器

第一步:新建Fckeditor.php类

最重要的一点就出来了..我把Fckeditor里面的fckeditor_php5.php这个文件写成如下插件形式: 名称就是./Library/Common/Plugin/Fckeditor.php 大致代码如下:

InstanceName = $instanceName ;
$this->BasePath = ‘/fckeditor/’ ;
$this->Width = ‘100%’ ;
$this->Height = ‘200’ ;
$this->ToolbarSet = ‘Default’ ;
$this->Value = ” ;

$this->Config = array() ;
}

public function Create()
{
echo $this->CreateHtml() ;
}
//…….

//后面的代码是和FCK里fckeditor_php5.php文件一样的.

//在后面加上 Fckeditor.php 里面这段代码.(一定要加否则会报错.)
public function FCKeditor_IsCompatibleBrowser()
{
global $HTTP_USER_AGENT ;

if ( !isset( $_SERVER ) ) {
global $HTTP_SERVER_VARS ;
$_SERVER = $HTTP_SERVER_VARS ;
}

if ( isset( $HTTP_USER_AGENT ) )
$sAgent = $HTTP_USER_AGENT ;
else
$sAgent = $_SERVER[‘HTTP_USER_AGENT’] ;

if ( strpos($sAgent, ‘MSIE’) !== false && strpos($sAgent, ‘mac’) === false && strpos($sAgent, ‘Opera’) === false )
{
$iVersion = (float)substr($sAgent, strpos($sAgent, ‘MSIE’) + 5, 3) ;
return ($iVersion >= 5.5) ;
}
else if ( strpos($sAgent, ‘Gecko/’) !== false )
{
$iVersion = (int)substr($sAgent, strpos($sAgent, ‘Gecko/’) + 6, 8 ) ;
return ($iVersion >= 20030210) ;
}
else if ( strpos($sAgent, ‘Opera/’) !== false )
{
$fVersion = (float)substr($sAgent, strpos($sAgent, ‘Opera/’) + 6, 4) ;
return ($fVersion >= 9.5) ;
}
else if ( preg_match( “|AppleWebKit/(d+)|i”, $sAgent, $matches ) )
{
$iVersion = $matches[1] ;
return ( $matches[1] >= 522 ) ;
}
else
return false ;
}
}
?>

第二步:将Fckeditor文件整合到您的ZF中
/**
* 加载FCKeditor
* @param string $content 编辑器内容 默认为空
* @param string $id 编辑器的ID
* @return Trs_Controller_Plugin_Fckeditor
*/
public static function fckAction($id,$content=”)
{
//加载FCK类
Zend_Loader::loadClass(‘Trs_Controller_Plugin_Fckeditor’);
//实例化这个类
$oFCKeditor = new Trs_Controller_Plugin_Fckeditor($id) ;
//这里是您放置FCK文件的路径.您要根据您自己的作改动啊..
$oFCKeditor->BasePath = “/Transee/public/resources/scripts/fckeditor/”;
//FCK皮肤
$oFCKeditor->Config[‘SkinPath’] = ‘/Transee/public/resources/scripts/fckeditor/editor/skins/silver/’ ;
$oFCKeditor->Width = ‘100%’;
$oFCKeditor->Height = ‘500’;
$oFCKeditor->Value = $content;
return $oFCKeditor;
}

第三步:在zf控制层(controller)调用fckeditor插件
我在此将fck放在了系统的公共函数中,这样前后台都可以随时调用
$this->view->fckEditor =Trs_Utils_SystemGlobal::fckAction(“id”);

第四步:在视图中显示Fckeditor编辑器

fckEditor->Create();
?>

OK,这样我们的目标就达到了。