Yafフレームの自動テンプレート機能をオフにし、指定したテンプレートを手動で呼び出す

1156 ワード

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