lamp+cakephp下配置fckeditor详解 --by heng

来源:互联网 发布:大数据平台架构 编辑:程序博客网 时间:2024/05/21 18:48
1.登录http://ckeditor.com/download/ 下载FCKeditor2.6.6(在页面最下方)

2.解压FCKeditor_2.6.6.zip得到fckeditor文件夹

3.拷贝fckeditor文件夹到 app/webroot/js/ 下

4.拷贝fckeditor.php, fckeditor_php4.php, fckeditor_php5.php到 app/vendors/ 目录下

5.创建 app/views/helpers/fck.php 文件

键入以下代码:

<?phpApp::import('Vendor', 'fckeditor');class FckHelper extends AppHelper {                    /**    * creates an fckeditor textarea    *     * @param array $namepair - used to build textarea name for views, array('Model', 'fieldname')    * @param stirng $basepath - base path of project/system    * @param string $content    */    function fckeditor($namepair = array(), $basepath = '', $content = array()){        $editor_name = 'data';        foreach ($namepair as $name){            $editor_name .= "[" . $name . "]";        }        $oFCKeditor = new FCKeditor($editor_name) ;        $oFCKeditor->BasePath = $basepath . '/js/fckeditor/' ;        $oFCKeditor->Value = $content ;   $oFCKeditor->Width = "100%";   $oFCKeditor->Height = "400";        $oFCKeditor->Create() ;                }      }  ?>

6.在需要用到fckeditor的controller里面加入
var $helpers = array('Html', 'Form', 'Fck');

7.在views 中加入

echo $fck->fckeditor(array('Model', 'field'), $html->base, $yourContentVariable); (其中Model和field需要自己决定,$yourContentVariable可选)(在add.ctp中第三个参数要设为null,才能避免warning)


(注:在controller的edit()方法中用set()方法设好变量名,在views下的edit.ctp下调用$fck->fckeditor()时,要设置第三个参数,如$news['News']['content'])


8.进入app/webroot/js/fckeditor/editor/filemanager/connectors/php
打开 config.php

1)改代码行 $Config['Enable'] = flase; 为 $Config['Enable'] = true;


2)改代码行 $Config['UserFilesPath'] = '/userfiles/'; 中的userfiles为自己想要的名字,如upload。然后在cakephp项目的同级目录下会出现upload文件夹。 (这个路径是基于http://localhost的绝对路径,用于构建文件夹存储上传的文件,图片,视频等)