zend-framework - Zend 框架 : Render multiple Views in one Layout

标签 zend-framework zend-view

我想使用 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/

相关文章:

zend-framework - Zend不同的 View 脚本?

zend-framework - 如何捕获 Zend View 输出而不是实际输出它

php - Zend_Db_Adapter::beginTransaction() 是否堆栈?

template-engine - Zend 表现力 : how to change layout using Zend View

javascript - 在zend中的html选择中选择更改后如何更新数据库

php - XenForo 模板编译器如何解释 xen :title tag?

zend-framework - 如何对对象使用 Zend Framework 的部分循环

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

php - Zend 导航菜单 Accordion

zend-framework - 禁用的表单元素未提交