[ZendFramework教程>>原创作品]

Zend Framework怎样结合Fckeditor编辑器

  • 时间:2008年09月30日 19:43:58
  • 浏览量:5603
  • 评论量:14
  • 作者:kylingood

      今天晚上没有什么事可做..俩个同学今天晚上也要加班..自己一个人在他们住的地方没事..就来写一篇关于Zend Framework 教程..

这个教程主要的功能是介绍如果在Zend Framework 里运用Fckeditor做为后台文章发布的 编辑器..我会分为二个部分来说明..

     第一个就是不运用Smarty如何配置Fckeditor编辑器.

     第二个就是运用Smarty作为网站开发的模板..

   OK!....下面就开始说明了..

    第一种:  用Zend Framework 开发.但是不需用要用到模板的情况:  我在这里先贴一张网站目录图片..

做为讲解图片.这样我想会更详细一些...开发网站目录如下图片所示:

    

 

    如大家所见...我是把结合Fckeditor写成一个Zend Framework 插件形式..这样就可以让整个站点调用到FCK...

   这样无论是前台和后台都行..

   OK!最重要的一点就出来了..我把Fckeditor里面的fckeditor_php5.php这个文件写成如下插件形式:

名称就如我网站目录用红包线划出来的为Fckeditor.php  它的代码大致辞如下:

<?php
/**  * Zend_Controller_Plugin_Abstract  */
require_once	'Zend/Controller/Plugin/Abstract.php';
class Custom_Controller_Plugin_Fckeditor extends Zend_Controller_Plugin_Abstract
{	
	public $InstanceName ;
 
	public $BasePath ;
 
	public $Width ;
 
	public $Height ;
 
	public $ToolbarSet ;
 
	public $Value ;
 
	public $Config ;
 
 
	public function __construct( $instanceName )
 	{
		$this->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_php5.php,文件改写了..接下来要做的就是在controller控制器里学会运用这个插件.
.比如说我有一个关于日志的控制器:

代码如下所示(ArticleController.php):
 

 
<?php
class ArticleController extends Zend_Controller_Action
{
 
public function init()
{
    $this->view->baseUrl = $this->_request->getBaseUrl();
}  
public function indexAction ()
{
    //调用下面FCK的方法. $this->fckAction('在这里编写您的日志!');
    echo $this->view->render('FCK.phtml'); //显示示FCK编辑器的模板
 
}
 
/*这里就是把FCK调用写成一个方法.这样在这个控制器内只要调用这个方法就可以*/
 
public function fckAction($content='')
{
   //加载FCK类
   Zend_Loader::loadClass('Custom_Controller_Plugin_Fckeditor');
 
   //实例化这个类
   $oFCKeditor = new Custom_Controller_Plugin_Fckeditor('FCKcontent') ;
 
  //这里是您放置FCK文件的路径.您要根据您自己的作改动啊..
  $oFCKeditor->BasePath = WEB_ROOT."public/scripts/fckeditor/";
 
  //FCK皮肤 
  $oFCKeditor->Config['SkinPath'] =
  WEB_ROOT.'public/scripts/fckeditor/editor/skins/silver/' ;
  $oFCKeditor->Width = '100%';
  $oFCKeditor->Height = '300';
  $oFCKeditor->Value = $content;
  $this->view->fckeditor = $oFCKeditor;
  } 
} 
?>
 
这样在我们的FCK.phtml文件里只要这样写就可以:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FCK使用实例</title>
</head>
<body>
<? $this->fckeditor->Create();?>
<!-- 您就在这里调用FCK!-->
</body>
</html>
 

到了这里...我们就完成了..第一个问题: 就是不运用Smarty如何配置Fckeditor编辑器...

现在我们要解决第二种方法:就是如何运用Smarty作为网站开发的模板..配置Fckeditor编辑器??

其实是大同小异...在你的(ArticleController.php):文件里..代码如下所示:

 <?php
 
class ArticleController extends Zend_Controller_Action
{	
 
    public function init()
    {
        $this->view->baseUrl = $this->_request->getBaseUrl();    
    }
 
    public function indexAction()
    {    //调用下面FCK的方法.
    	$this->fckAction('在这里编写您的日志!');
       	//显示FCK编辑器的模板
       $this->smarty->display('FCK.phtml');
    }
 
     /*这里就是把FCK调用写成一个方法.这样在这个控制器内只要调用这个方法就可以*/
     public function fckAction($content='')
    {
        //加载FCK类
        Zend_Loader::loadClass('Custom_Controller_Plugin_Fckeditor');
        //实例化这个类
        $oFCKeditor = new Custom_Controller_Plugin_Fckeditor('FCKcontent') ;
        //这里是您放置FCK文件的路径.您要根据您自己的作改动啊..
        $oFCKeditor->BasePath = WEB_ROOT."public/scripts/fckeditor/";
        //FCK皮肤
       	$oFCKeditor->Config['SkinPath'] =
        WEB_ROOT.'public/scripts/fckeditor/editor/skins/silver/' ;
        $oFCKeditor->Width  = '100%';
        $oFCKeditor->Height = '300';
      	$oFCKeditor->Value = $content;
        //注意:唯一就是这里不同
      	$this->smarty->assign("oFCKeditor",$oFCKeditor);
 
	}
}
?>
 现在我们要在运用了Smarty模板里使用FCK编辑器..就可以这样:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FCK使用实例</title>
</head>
<body>
<{$oFCKeditor->create()}>
<!-- 您就在这里调用FCK! 我这里Smarty是用了<{}> 作分隔符.
您可能会和我的不一样..把这个换成你自己的就可以用了 -->
</body>
</html>
 

OK!这样你就可以在任何时候使用FCKeditor这个编辑器了...只要你自己按这个教程来写..不过可能有比我更 好的方法..我这里只是一种....

因为刚学Zend Framework .所以有很多不太会的东西...有的时候可能是错误的...希望大家可以批评指正...

最后给大写一张..我这个博客的图:看看..我运用FCK的效果..呵呵...

效果图片:

上面这图片就是我自己的博客FCK编辑器...好了..就写到这里...希望和广大的PHP爱好者多多交流....朋友可以给我留言...

原创文章如转载,请注明:转载OOPHP开源博客 [ http://www.oophp.cn/ ]

上一篇:休息期间,认识到自己需要去学习的地方有很... 下一篇:本人打算写系列Zend Framewor...

: Baidu搜藏 QQ书签 Google书签 Del.icio.us POCO网摘 Yahoo书签 新浪ViVi 365Key网摘 天极网摘 和讯网摘 Windows Live 提交新发现,Dig it

用户推荐文章
相关文章
网友评论
发表评论

会员的头像

: 请选个帅照吧!
:  *  尊姓大名大名(2-30字).
:  *  来了就多说几句吧(4-250字)
:  *  没办法,只为防机器人@_@