fckeditor集成到php zend framework框架中

 

我们要做的是把Fckeditor写成一个Zend Framework 插件形式..这样就可以让整个站点调用到FCK... 这样无论是前台和后台都行
1.获得fckeditor 编辑器。 我用的是2.6.3版本,解压后放在public/scripts目录下
很多文件我们不需要放到我们的程序中,可以删除:
editor目录 、fckconfig.js、 fckeditor.php、fckeditor_php5.php、fckpackager.xml、fckeditor.js、 fckstyles.xml、
fcktemplates.xml、license.txt这几个保
留,其余的全部去除;
子目录下:editor/filemanager/connectors目录中 把php目录留下(上传用什么方法就留下什么),其余的方法目录删
除(注意留下test.html 和 uploadtest.html)
editor/lang语言 把 en.js 、 zh.js 、 zh-cn.js 留下,其余全部删除
2.修改 fckeditor/fckconfig.js

①确认以下两值为php(fckeditor 2.6.3下已默认为php):
var
 _FileBrowserLanguage = 'php'

var _QuickUploadLanguage = 'php'
②修改变量以下值:
FCKConfig.AutoDetectLanguage = true
 ; //如果你的用户是多语言环境,请设为true,如果只是中文用户,改为false

FCKConfig.DefaultLanguage = 'zh-cn' ;
//添加中文字体
FCKConfig.FontNames = '宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
FCKConfig.FontSizes = '9px;10px;11px;12px;13px;14px;16px;18px;24px;36px' ;
③在IE中直接回车是产生一个p标签,这样两行间距太大,如果用SHIFT+ENTER这样就是产生BR标签.间距不大,不过这样太麻烦了,那么我们把他们替换下。
FCKConfig.EnterMode = 'br'
 ; // p | div | br

FCKConfig.ShiftEnterMode = 'p' ; // p | div | br
3.把fckeditor与zf整合

把Fckeditor里面的fckeditor_php5.php这个文件写成如下插件形式,将其放在application/models/下,命名为Fckeditor.php
/**此代码为类代码*/

class Model_Fckeditor extends Zend_Controller_Plugin_Abstract //要继承这个类
{
/**
* Name of the FCKeditor instance.
*
* @access protected
* @var string
*/

public $InstanceName ;
/**
* Path to FCKeditor relative to the document root.
*
* @var string
*/

public $BasePath ;
/**
* Width of the FCKeditor.
* Examples: 100%, 600
………………
//后面的代码是和FCK里fckeditor_php5.php文件一样的.
4.把/Scripts/目录下关闭重写,建立.haccess文件内容:RewriteEngine off(不关闭重写会导至调不到FCK文件,发生Zend_Controller_Dispatcher_Exception异常)

5.在控制层文件中对调用fckeditor

public
 function
 indexAction(
)

{
// action body
//Zend_Loader::loadClass('Model_Fckeditor');
//实例化这个类
$oFCKeditor = new Model_Fckeditor( 'content' ) ;
//这里是您放置FCK文件的路径.您要根据您自己的作改动啊
$oFCKeditor ->BasePath = $this ->view ->baseUrl ( ) .'/scripts/fckeditor/' ;
//FCK皮肤
$oFCKeditor ->Config [ 'SkinPath' ] =$this ->view ->baseUrl ( ) .'/scripts/fckeditor/editor/skins/office2003/' ;
$oFCKeditor ->Width = '100%' ;
$oFCKeditor ->Height = '300' ;
$oFCKeditor ->Value = ' ' ;
$this ->view ->fckeditor = $oFCKeditor ;
}
6.在视图中显示

<table cellpadding="0"
 cellspacing="0"
 width=100
%><tr><td>
标题:</td><td><input type='text' name='title' /></td></tr>
<tr><td>内容:</td><td>
<?php
$this ->fckeditor ->Create ( ) ;
?>
</td></tr></table>
7.Fckedotor 上传文件(file flash image media)调试

  • 打开/fckeditor/editor/filemanager/connectors/php/config.php找到:
$Config['Enabled'] = false
改成:
$Config['Enabled'] = true
设置上传存放目录:
找到:
$Config['UserFilesPath'] = '/userfiles/'
改成:
$Config['UserFilesPath'] = '/uploads/' //此时文件路径在public下,这个文件夹得自己建!别忘了放一个.htaccess
  • 使用当前时间戳做为文件名
打开fckeditor/editor/filemanager/connectors/php/commands.php
找到
$sFileName = $oFile['name'] ;
改为
$sFileName = time().".".strtolower(array_pop(explode(".",$oFile['name'])));
  • 指定不同类型的文件上传到不同的目录中(图片在uploads/image/下,文件在uploads/file/下,flash在uploads/flash/下,视频在uploads/media/下)
打开fckeditor/editor/filemanager/connectors/php/config.php,重置以下项
$Config['QuickUploadPath']['File']= $Config['UserFilesPath'] .'file/';
$Config['QuickUploadPath']['Image'] = $Config['UserFilesPath'] .'image/' ;
$Config['QuickUploadPath']['Flash'] = $Config['UserFilesPath'] .'flash/';
$Config['QuickUploadPath']['Media'] = $Config['UserFilesPath'] .'media/';

8.备注

用$_POST['content']得到fckeditor的值。上传图片不能超过两兆!
还有很多可以自定义,大多是修改fckconfig.js!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值