問題描述
我正在學習 ZF2.0 測試版.在 ZF1 中,我們可以在控制器中動態更改布局:
I am learning ZF2.0 beta. In ZF1 we can change layout on the fly in controller:
Zend_Layout::getMvcInstance()->setLayout('layoutname');
但在 ZF2.0 ZendLayout 類中沒有方法 getMvcInstance().我認為可以使用依賴注入來實現,但不確定.
But in ZF2.0 ZendLayout class doesn't has method getMvcInstance(). I think that it can be made using dependency injections but not sure.
推薦答案
ZF2 正在大量開發中,不能保證現在的工作方式,當 ZF2 達到穩定狀態時會是它的工作方式.
The ZF2 is heavily under development and no guarantee can be made the way it works now, will be the way it works when ZF2 reaches a stable state.
>
但是,來自 ZendMvc 的新視圖層最近已合并,因此您現在應該能夠執行此操作(使用當前主控):
However, the new view layer from ZendMvc is recently merged so you should be able to do this now (with current master):
public function somethingAction ()
{
// Do some intelligent work
$this->layout('layout/different');
}
這篇關于在 Zend Framework 2.0 的控制器中更改布局的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!