Zend Framework - 对控制器中的不同操作使用通用标头?
我尝试阅读此处找到的问题: 模块配置和布局配置zend 框架 它被描述为我需要了解的有关布局的一切 - 但是 - 恐怕我发现它有点难以理解。
我有许多 Zend 控制器:
class FirstController extends Zend_Controller_Action {
public function init() { /* stuff */ }
public function indexAction() { /* stuff */ }
public function indexBrowse() { /* stuff */ }
}
class SecondController extends Zend_Controller_Action {
// stuff
}
class ThirdController extends Zend_Controller_Action {
// stuff
}
我需要它们具有以下排列。
- 第一控制器和第二个控制器共享一个标头
- FirstController - indexAction 和 browserAction 共享一个附加标头
- Thirdcontroller - 有它自己的标头或可能“没有标头”(对于 ajax)
就目前情况而言,我在 view/script/< 中得到了巨大的复制;actionname>.phtml 文件 http://framework. zend.com/manual/en/zend.layout.quickstart.html
有更多信息,但我无法找到让我明白这一切的关键信息。
从上面的第一个文档中,我猜测以下内容会进入我的 application.ini
文件,
resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
但是我是否期望创建一个名为“Layouts”的文件夹,或者我应该使用某种 views/通用文件夹?该文件是否名为
layout.php
?
那么,在 layout.php
中,我是否正确理解
<div id="content"><?php echo $this->layout()->content ?></div>
Will 渲染单个操作的 PHTML
文件?并使
public function anotherAction() {
$this->_helper->layout->setLayout('foobaz');
}
整个操作使用不同的布局文件(布局文件夹中名为“foobaz.php”的文件)?
感谢您花时间为我解决这个问题。
I've tried reading the question found HERE: Module configuration and layout configuration in zend framework It was described as being everything I need to know about layouts - but - I'm afraid I'm finding it a bit difficult to understand.
I've got a number of Zend controllers:
class FirstController extends Zend_Controller_Action {
public function init() { /* stuff */ }
public function indexAction() { /* stuff */ }
public function indexBrowse() { /* stuff */ }
}
class SecondController extends Zend_Controller_Action {
// stuff
}
class ThirdController extends Zend_Controller_Action {
// stuff
}
I need them to have the following arrangement.
- FirstController & Second Controller share a header
- FirstController - indexAction and browseAction share an additional header
- Thirdcontroller - has it's own header or possibly "no header" (for ajax)
As it stands, I'm getting tremendous replication in the view/script/<actionname>.phtml
file http://framework.zend.com/manual/en/zend.layout.quickstart.html
Has more information but I've not been able to find the key pieces of information that bring this all home for me.
From the first document above I'm guessing the following goes into my application.ini
file
resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
But am I expected to create a folder called "Layouts" or should I be using some sort of views/common
folder? Is the file then called layout.php
?
Then, inside the layout.php
am I understanding correctly that
<div id="content"><?php echo $this->layout()->content ?></div>
Will render the individual action's PHTML
file? and
public function anotherAction() {
$this->_helper->layout->setLayout('foobaz');
}
Would make the entire action use a different layout file (one in the layouts folder called 'foobaz.php')?
Thanks for taking the time to clear this up for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你说得对,
应该用不同的布局渲染页面,并简单地在layout()->content占位符中输出视图内容。
另一种方法是使用单一布局,并使用部分加载不同的标题。
在你的行动中你可以有
然后在你的布局中你可以这样做
这可能是在顶部。
Yea, you have it right,
Should render the page with a different layout, and simply output the views contents in the layout()->content place holder.
Another way would be to have a single layout, and use partials to load different headers.
In your action you could have
Then in your layout you could just do this
This is probably over the top.