使用 Zend Framework 在更高的脚本路径中渲染视图
让我们假设控制器中有以下代码:
$this->view->addScriptPath('dir1/views/scripts');
$this->view->addScriptPath('dir2/views/scripts');
$this->render('index.phtml');
其中 dir1/views/scripts 包含 2 个文件:
-index.phtml
-table.phtml
和 dir2/views/scripts:
-table.phtml
现在,它将在 dir1 中渲染 index.phtml,因为 dir 2 没有 index.phtml。
Index.phtml 看起来像:
<somehtml>
<?= $this->render('table.phtml') ?>
</somehtml>
这就是我开始感到困惑的地方。我希望它能够渲染添加到脚本路径堆栈的最后一个目录中的 table.phtml,但事实并非如此。
我的问题有简单的解决方案/解释吗?
Lets assume the following code within a controller:
$this->view->addScriptPath('dir1/views/scripts');
$this->view->addScriptPath('dir2/views/scripts');
$this->render('index.phtml');
Where dir1/views/scripts contains 2 files:
-index.phtml
-table.phtml
And dir2/views/scripts:
-table.phtml
Now, it will render the index.phtml in dir1 since dir 2 doesn't have an index.phtml.
Index.phtml looks something like:
<somehtml>
<?= $this->render('table.phtml') ?>
</somehtml>
This is where the confusion starts for me. I would expect it to render the table.phtml in the last directory added to the script path stack, but it doesn't.
Is there a simple solution/explanation to my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎路径是按 LIFO 顺序使用的。
查看
viewRednderer
和view
源文件以了解其工作原理。Seems that paths are used in LIFO order.
Take a look at
viewRednderer
andview
source files to see how does it work.你可以使用
更具体的
u can use
that is more specific
我最终扩展了 Zend_View 并添加了 renderParent 函数:
I ended up extending Zend_View and adding the function renderParent: