2014-04-16 82 views

回答

1

的爾康論壇使用你所提到的方法:https://github.com/phalcon/forum/blob/master/app/views/partials/top-menu.volt

更好的解決方案是使用佈局用條件

你的前端控制器可以從BaseFrontendController繼承,並選擇在自己的初始化佈局:

class BaseFrontendController extends BaseController { 

public function initialize() 
{ 
    parent::initialize() 
    if ($this->authenticated) { 
     $this->view->setTemplateBefore('frontend-authenticated'); 
    } else { 
     $this->view->setTemplateBefore('frontend-guest'); 
    } 
} 

然後就延長從任何控制器BaseFrontendController你在前面有:

class IndexController extends BaseFrontendController { 

public function initialize() 
{ 
    parent::initialize() 
} 
} 

佈局文件通常很短,只是有一些包括。在這裏閱讀更多關於它們的信息:

http://docs.phalconphp.com/en/latest/reference/views.html#hierarchical-rendering