我想使用 Zend_Layout 生成一个动态站点。
我的布局 (/application/layouts/scripts/layout.phtml) 包含以下几行:
...
<body>
<?php echo $this->render('header.phtml') ?>
<div id="content"><?php echo $this->layout()->content ?></div>
<?php echo $this->render('footer.phtml') ?>
</body>
...
如果我浏览到我的索引 Controller 索引操作 - Zend 会自动呈现 $this->layout()->content 内的索引 View (application/views/scripts/index/index.phtml)。
现在我想在布局中呈现不同 Controller 操作的 View 。
所以我生成了一个新的 Controller 身份验证,其中包含一个显示登录表单的操作登录。
我将布局更改为:
...
<body>
<?php echo $this->render('header.phtml') ?>
<div id="content"><?php echo $this->layout()->content ?></div>
<div id="login"><?php echo $this->layout()->login ?></div>
<?php echo $this->render('footer.phtml') ?>
</body>
...
当我浏览到索引/索引时,我想在此操作中定义 Zend 应在 $this->layout()->login 内呈现 auth/login View ,例如 $this->layout()- 内的新闻/列表- > 内容。
索引/索引不仅仅是一种页面布局 -
和 auth/login 和 news/list 一种小部件
这该怎么做?
最佳答案
第一个建议是不惜一切代价避免使用 Action View 助手,无论如何它可能会在 ZF 2.0 中被删除。 ( ZF-5840 ) ( Why the actionstack is evil )
这与question I asked有关- bittarman 的回答非常有用。实现类似功能的最佳方法是拥有一个可以生成“登录”区域的 View 助手。 My_View_Helper_Login
例如。然后你的布局可以调用 $this->login()
,user/login
的 View 脚本也是如此。 .只要有index/index
呈现来自 news/list
的内容只需将请求从 Controller 转发到另一个 Controller /操作。 $this->_forward('list', 'news');
关于zend-framework - Zend 框架 : Render multiple Views in one Layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1314434/