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');
}
}