問(wèn)題描述
我正在學(xué)習(xí) ZF2.0 測(cè)試版.在 ZF1 中,我們可以在控制器中動(dòng)態(tài)更改布局:
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 類中沒(méi)有方法 getMvcInstance().我認(rèn)為可以使用依賴注入來(lái)實(shí)現(xiàn),但不確定.
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 正在大量開(kāi)發(fā)中,不能保證現(xiàn)在的工作方式,當(dāng) ZF2 達(dá)到穩(wěn)定狀態(tài)時(shí)會(huì)是它的工作方式.
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.
>
但是,來(lái)自 ZendMvc 的新視圖層最近已合并,因此您現(xiàn)在應(yīng)該能夠執(zhí)行此操作(使用當(dāng)前主控):
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');
}
這篇關(guān)于在 Zend Framework 2.0 的控制器中更改布局的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!