文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>实现 Zend_View_Abstract: 在 ZF 中使用 Smarty 作为View

实现 Zend_View_Abstract: 在 ZF 中使用 Smarty 作为View

时间:2008-04-16  来源:manbuzhe0301

学习摘记: Pratical Web 2.0 Application With PHP
@date:2008-04-16
@autor: lyw0301

Zend_View 是一个可以协助你组织视图逻辑的类, 它并不使用特定的模版系统,
但我们如果之前有Smarty的需要,我们完全可以把它集成到 Zend_View 中,
示范代码如下:

        public function __construct()
        {
            $config = Zend_Registry::get('config');
            require_once('Smarty/Smarty.class.php');
            $this->_engine = new Smarty();
            $this->_engine->template_dir = $config->paths->templates;
            $this->_engine->compile_dir = sprintf('%s/tmp/templates_c',
                                                  $config->paths->data);
            $this->_engine->plugins_dir = array($config->paths->base .
                                                '/include/Templater/plugins',
                                                'plugins');
        }
        public function getEngine()
        {
            return $this->_engine;
        }
        public function __set($key, $val)
        {
            $this->_engine->assign($key, $val);
        }
        public function __get($key)
        {
            return $this->_engine->get_template_vars($key);
        }
        public function __isset($key)
        {
            return $this->_engine->get_template_vars($key) !== null;
        }
        public function __unset($key)
        {
            $this->_engine->clear_assign($key);
        }
        public function assign($spec, $value = null)
        {
            if (is_array($spec)) {
                $this->_engine->assign($spec);
                return;
            }
            $this->_engine->assign($spec, $value);
        }
        public function clearVars()
        {
            $this->_engine->clear_all_assign();
        }
        public function render($name)
        {
            return $this->_engine->fetch(strtolower($name));
        }
        public function _run()
        { }
    }
?>

相关阅读 更多 +
排行榜 更多 +
西安交大通

西安交大通

生活实用 下载
长江云通

长江云通

生活实用 下载
translatez

translatez

生活实用 下载