把Fckeditor整合到Zend Framework View_Helper里

看到过把fckeditor放进Controller和直接放在模板里的,虽然能成功运行,但总感觉都和Zend Framework规范有点不太相符,个人觉得放在视图助手里科学一点。

Zend Framework v1.52
Fckeditor v2.6.3 beta

其中fckeditor放在public/js/fckeditor目录下

代码如下:

[-]View Code LANGUAGE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
< ?php
/**************************
@Author  : evila
@Update  :
@Content : Fckeditor 视图辅助类
**************************/
 
class Zend_View_Helper_Fckeditor
{
 function fckeditor($InstanceName='',$value='',$width=800,$height=500,$toolbar='Default')
 {
  require_once 'js/fckeditor/fckeditor.php'
  $iFCKeditor = new FCKeditor($InstanceName)
  $iFCKeditor-&gtBasePath = './js/fckeditor/'
  $iFCKeditor-&gtWidth  = "$width"
  $iFCKeditor-&gtHeight = "$height"
        $iFCKeditor-&gtValue = "$value"
  $iFCKeditor-&gtToolbarSet = "$toolbar"
 
  return $iFCKeditor-&gtCreateHtml()
 }
}

在模板文件里只需 <?php echo $this->fckeditor(’InstanceName’,'test_text’);?> 调用即可(参数自行输入)。
插件fckeditor引导文件 require_once ‘js/fckeditor/fckeditor.php’; 也可用Zend::Loader()加载,但是根据官方手册介绍,效率是一样的

Tags: , ,

Leave a Reply