在Zend Framework 2.0的控制器中更改布局 [英] Change layout in the controller of Zend Framework 2.0

查看:73
本文介绍了在Zend Framework 2.0的控制器中更改布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 ZF2.0 beta .在ZF1中,我们可以在控制器中即时更改布局:

Zend_Layout::getMvcInstance()->setLayout('layoutname');

但是在 ZF2.0 中,Zend \ Layout类没有方法getMvcInstance().我认为可以使用依赖项注入来实现,但不确定.

解决方案

ZF2正在大量开发中,无法保证它现在的工作方式,这将是ZF2达到稳定状态后的工作方式.

但是,最近合并了Zend \ Mvc中的新视图层,因此您应该能够(使用当前的主控器)立即执行此操作:

public function somethingAction () 
{
    // Do some intelligent work

    $this->layout('layout/different');
}

I am learning ZF2.0 beta. In ZF1 we can change layout on the fly in controller:

Zend_Layout::getMvcInstance()->setLayout('layoutname');

But in ZF2.0 Zend\Layout class doesn't has method getMvcInstance(). I think that it can be made using dependency injections but not sure.

解决方案

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.

However, the new view layer from Zend\Mvc 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的控制器中更改布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆