网管

返回首页
当前位置: 网管>网站建设>php>

Zend Framework整合Smarty代替Zend_View

时间:2009-09-15 23:17来源:未知 作者:admin 点击:
通过Zend_View_Interface接口使用模板系统 实现一个与Zend_View兼容的模板系统是很简单的。你只需要实现Zend_View_Interface接口即可,该接口定义了要实现兼容的最低要求。 定义一个Smarty.php,放在Zend/Vi
  通过Zend_View_Interface接口使用模板系统

实现一个与Zend_View兼容的模板系统是很简单的。你只需要实现Zend_View_Interface接口即可,该接口定义了要实现兼容的最低要求。

定义一个Smarty.php,放在Zend/View/下
<?php
require_once('Smarty/Smarty.class.php');
require_once('Interface.php');

/**
* @copyright 2008 - 
* @author cooldark
* @access public
* @todo 整合Smarty模板到Zend_View,代替Zend本身的模板
*
*/
class Zend_View_Smarty implements Zend_View_Interface {

/**
* Smarty对象
*
* @var Smarty
*/
private $_smarty;

/**
* 构造函数,初始化
*
* @param String $_smartyPath
* @param Array $_smartyParams
*/
public function __construct($_smartyPath = null, $_smartyParams = array()) {
$this -> _smarty = new Smarty();

if (null != $_smartyPath) {
$this -> setScriptPath($_smartyPath);
}

foreach ($_smartyParams as $key => $value) {
$this->_smarty->$key = $value;
}

}

/**
* 获得对象视图引擎并返回
*
* @return Smarty
*/
public function getEngine() {
return $this -> _smarty;
}

/**
* 设置模板文件所在目录
*
* @param String $path
*/
public function setScriptPath($path) {
if (is_readable($path)) {
$this -> _smarty -> template_dir = $path;
}

throw new Exception('Invalid path provided!');
}

/**
* 获取模板文件所在目录
*
* @return Array
*/
public function getScriptPaths() {
return array($this -> _smarty -> template_dir);
}

public function setBasePath($path, $prefix = 'Zend_View') {
return $this -> setScriptPath($path);
}

public function addBasePath($path, $prefix = 'Zend_View') {
return $this -> setScriptPath($path);
}

public function __set($key, $val) {
$this -> _smarty -> assign($key, $val);
}

public function __get($key) {
return $this -> _smarty -> get_template_vars($key);
}

public function __isset($key) {
return (null !== $this -> _smarty -> get_template_vars($key));
}

public function __unset($key) {
$this -> _smarty -> clear_assign($key);
}

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
推荐内容