Yaf框架默认是开启自动加载模板的,如要关闭自动加载,可在Bootstrap.php里设置,如:
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
public function _initConfig()
{
Yaf_Registry::set('config', Yaf_Application::app()->getConfig());
Yaf_Dispatcher::getInstance()->autoRender(FALSE); // 关闭自动加载模板
}
}
在控制器里手动调用的方式有2种:
一,调用当前$this->_module目录下的模版,下面是手动调用view/index/目录下hello.phtml模板
<?php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
$this->getView()->assign("content", "Hello World");
$this->display('hello');
}
}二,随意调用view目录下的模板,下面是调用view/test/world.phtml模板<?php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
$this->getView()->assign("content", "Hello World");
$this->getView()->display('test/world.phtml');
}
}

本文介绍如何在Yaf框架中关闭默认的自动加载模板功能,并提供了两种手动加载模板的方法。一种是在当前模块目录下调用模板,另一种是在任意view目录下调用模板。
6503

被折叠的 条评论
为什么被折叠?



