关闭Yaf框架里的自动加载模板功能和手动调用指定模板

来源:互联网 发布:日本 社会问题 知乎 编辑:程序博客网 时间:2024/05/20 13:16
Yaf框架默认是开启自动加载模板的,如要关闭自动加载,可在Bootstrap.php里设置,如:
<?phpclass 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模板

<?phpclass IndexController extends Yaf_Controller_Abstract{    public function indexAction()    {        $this->getView()->assign("content", "Hello World");        $this->display('hello');    }}
二,随意调用view目录下的模板,下面是调用view/test/world.phtml模板
<?phpclass IndexController extends Yaf_Controller_Abstract{    public function indexAction()    {        $this->getView()->assign("content", "Hello World");        $this->getView()->display('test/world.phtml');    }}

原创粉丝点击