php 如何在 Zend Framework 中切换布局文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1615956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:16:30  来源:igfitidea点击:

How to switch layout files in Zend Framework?

phpzend-frameworklayoutzend-viewzend-layout

提问by Andrew

I'm sure it's a simple one-liner, but I can't seem to find it.

我确定这是一个简单的单线,但我似乎找不到它。

How can I use a different layout file for a particular action?

如何为特定操作使用不同的布局文件?

Update:This worked for me, thanks!

更新:这对我有用,谢谢!

// Within controller
$this->_helper->_layout->setLayout('other-layout') //other-layout.phtml

//Within view script
<?php $this->layout()->setLayout('other-layout'); ?>

回答by Josh Lindsey

From inside a Controller:

从控制器内部:

$this->_helper->layout->setLayout('/path/to/your/layout_script');

(via these docs)

(通过这些文档

EDIT: I should mention that the path is relative to whatever your layout directory is (by default, it's application/layouts/scripts/)

编辑:我应该提到路径是相对于您的布局目录的任何内容(默认情况下,它是application/layouts/scripts/

回答by Md Moin Uddin

You can also use like this

你也可以这样使用

// Within controller
Zend_Layout::getMvcInstance()->setLayout('layout_name');

//Within view script

<?php $this->layout()->setLayout('layout_name'); ?>

Your layout must be in /layouts/scripts/ folder, otherwise you need to specify the path also. No need to write .phtml, just name of the layout

您的布局必须在 /layouts/scripts/ 文件夹中,否则您还需要指定路径。无需编写.phtml,只需布局名称