标题: ZF与FCKeditor集成完全攻略(包括上传、浏览服务器图像)
Haohappy
超级版主
Rank: 8Rank: 8
PHPEye站长


UID 2
精华 11
积分 110
帖子 285
翻译 6
原创 1
阅读权限 150
注册 2007-5-2
状态 离线
发表于 2007-7-29 23:25  资料  短消息  加为好友  添加 haohappy 为MSN好友 通过MSN和 haohappy 交谈
ZF与FCKeditor集成完全攻略(包括上传、浏览服务器图像)

FCKedtior是目前最流行和最强大的HTML在线编辑器之一,非常好用。本文介绍如何集成Zend framework和FCKeditor。

首先基本配置的修改,网上很多文章都有写,在此不再多说,最权威的资料当然是FCKeditor官网的:
http://wiki.fckeditor.net/Developer%27s_Guide/Integration/PHP

最主要是修改fckconfig.js文件。

下面说说和ZF的集成,以及一些需要注意的地方:

1。FCKeditor的安装
FCKeditor需要放在public的目录,即通过网站可以访问到的目录下。比如wwwroot/js/FCKeditor。

新版的FCKeditor需要加载一些配置XML文件,所以在你的Apache配置中,XML文件不能转向到ZF的bootstrap。
另外,下面的一些功能需要用到一些PHP文件,而在ZF项目中通常禁用对PHP文件的直接访问。

这些你都可以通过修改Apache服务器的URL重写规则来搞定:
RewriteCond %{REQUEST_URI} !^.*(\.html|\.xml|\.css|\.js|\.gif|\.png|\.jpg|\.jpeg)$|.*(FCKeditor).*

这样,XML文件不转向至index.php,而访问地址中包含FCKeditor字符的php文件也能直接访问。


2。集成

在你的模板文件中(即ZF的View部分,例如views/article/articleForm.php),需要添加表单的地方加入以下代码:

PHP代码如下:

<?php 
    $oFCKeditor 
= new FCKeditor('ArticleBody') ;
    
$oFCKeditor->BasePath "/js/FCKeditor/";
    
$oFCKeditor->Width  '600';
    
$oFCKeditor->Height '500';
    if(
$this->article->ArticleBody!=''){
        
$oFCKeditor->Value $this->article->ArticleBody;
    }else{
        
$oFCKeditor->Value '';
    }
    
$oFCKeditor->Create(); 
    
?>


这个表单可以同时用于添加和编辑文章,当文章内容不为空(即当前操作为编辑时),显示文章内容,否则为新增文章,表单内容为空。

提交本页面后,你可以使用$_POST['ArticleBody']来获取表单中的文字内容。


2。浏览服务器图像
在写文章的时候,希望可以直接浏览服务器上的图像,添加到文章里,就需要这个功能。
FCKeditor中本功能的实现在FCKeditor\editor\filemanager\browser\default\connectors\php目录的几个文件。

我们只需要修改
FCKeditor\editor\filemanager\browser\default\connectors\php\config.php

PHP代码如下:
$Config['Enabled'] = true //一定要设定成true,本功能才启用
$Config['UserFilesPath'] = '/UserFiles/' ;  //图像文件所在的目录,你可以根据自己的需要修改


设定好后你可以通过ftp上传图像文件到/UserFiles/image目录下,测试一下是否可以浏览。

注意:默认情况下,FCKeditor的图像文件要放在UserFiles下的image目录里,而不能直接放在UserFiles目录里。

3。图像上传

如果你想在写文章的时候,直接上传图像到服务器,然后插入到文章中,可以用这个功能。
FCKeditor中本功能的实现在FCKeditor\editor\filemanager\upload\php目录的几个文件。

我们也只需要修改该目录下的config.php

PHP代码如下:
$Config['Enabled'] = true ;
$Config['UserFilesPath'] = '/UserFiles/' //上传目录的路径,通常和上面的浏览部分的路径设成一样的
$Config['UseFileType'] = true ;  //不同上传文件类型是否分目录放置,图像文件会自动被上传到/UserFiles/image目录下,Flash则在/UserFiles/flash目录下


注意:UserFiles目录和其下的image目录要可写权限。

[ 本帖最后由 Haohappy 于 2007-7-30 08:20 编辑 ]





互助共享,共同成长。
顶部
kylingood
版主
Rank: 7Rank: 7Rank: 7



UID 104
精华 1
积分 10
帖子 45
翻译 0
原创 0
阅读权限 100
注册 2007-6-22
状态 离线
发表于 2007-7-31 21:46  资料  短消息  加为好友 
经典。收下了~~~~~~~~~

顶部
kuco
新手上路
Rank: 1



UID 192
精华 0
积分 0
帖子 8
翻译 0
原创 0
阅读权限 10
注册 2007-7-17
状态 离线
发表于 2007-8-3 22:07  资料  短消息  加为好友 
支持

顶部
raylzw
新手上路
Rank: 1



UID 77
精华 0
积分 0
帖子 2
翻译 0
原创 0
阅读权限 10
注册 2007-6-16
状态 离线
发表于 2007-8-12 05:15  资料  短消息  加为好友 
支持.先收了,

顶部
scauren
新手上路
Rank: 1



UID 118
精华 0
积分 0
帖子 5
翻译 0
原创 0
阅读权限 10
注册 2007-6-26
状态 离线
发表于 2007-8-13 23:04  资料  短消息  加为好友 
VIEW用到smarty的怎么做呢?

顶部
leinchu
新手上路
Rank: 1



UID 526
精华 0
积分 0
帖子 3
翻译 0
原创 0
阅读权限 10
注册 2007-11-7
状态 离线
发表于 2007-11-7 11:48  资料  短消息  加为好友  添加 leinchu 为MSN好友 通过MSN和 leinchu 交谈
fckeditor_php5.php另存为:libs/Custom/Fckeditor.php,类名改为:Custom_FCKeditor.
controller:
public function fckAction()
        {
                Zend_Loader::loadClass('Custom_Fckeditor');
                $oFCKeditor = new Custom_Fckeditor('ArticleBody') ;
                $oFCKeditor->BasePath = "/scripts/FCKeditor/";
                $oFCKeditor->Width  = '600';
                $oFCKeditor->Height = '500';
                /*if($this->article->ArticleBody!=''){
                        $oFCKeditor->Value = $this->article->ArticleBody;
                }else{
                }*/
                $oFCKeditor->Value = '';
                $this->view->oFCKeditor=$oFCKeditor;
        }

smarty view:
<{include file="header.html"}>
<{ $oFCKeditor->create() }>
<{include file="footer.html"}>

[ 本帖最后由 leinchu 于 2007-11-7 11:50 编辑 ]

顶部
Dereky
新手上路
Rank: 1



UID 386
精华 0
积分 0
帖子 9
翻译 0
原创 0
阅读权限 10
注册 2007-9-19
状态 离线
发表于 2007-12-15 17:10  资料  短消息  加为好友 
安装楼上的方法安装不行啊,报告:
Fatal error: Call to undefined function FCKeditor_IsCompatibleBrowser() in
。。。

顶部
Dereky
新手上路
Rank: 1



UID 386
精华 0
积分 0
帖子 9
翻译 0
原创 0
阅读权限 10
注册 2007-9-19
状态 离线
发表于 2007-12-15 17:16  资料  短消息  加为好友 
需要修改这个
fckeditor_php5.php
在最后增加
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 ;
        }

然后 105行改成
return $this->FCKeditor_IsCompatibleBrowser() ;

顶部
edwin
新手上路
Rank: 1



UID 663
精华 0
积分 0
帖子 7
翻译 0
原创 0
阅读权限 10
注册 2007-12-19
状态 离线
发表于 2007-12-20 22:24  资料  短消息  加为好友 
也参加讨论一下:
既然提到与zf 完全整合,我想还是要考虑一下几个问题,不知道楼主的意见如何:
1 fckAction将多次出现,如何抽象他
2 zf的public既然不建议有其他的php文件,我们还是要将fck的php file移植,不知道楼主是怎么想的?

顶部
古树
新手上路
Rank: 1



UID 494
精华 0
积分 0
帖子 4
翻译 0
原创 0
阅读权限 10
注册 2007-10-28
状态 离线
发表于 2008-1-5 19:43  资料  短消息  加为好友 
快速上传、浏览服务器、创建目录均不支持中文文件名。。。

寻求最完美的解决办法??

顶部
 


PHPEye开源社区


当前时区 GMT+8, 现在时间是 2009-1-9 08:50

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.028592 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - PHPEye开源社区 - Archiver