如何在Zend中使用来自不同模块的局部视图?

lev*_*ele 10 zend-framework zend-view

我正试图从另一个模块访问foo中的局部视图.简化的文件结构:

application/
    modules/
        foo/
            index.phtml
        bar/
            partial.phtml
Run Code Online (Sandbox Code Playgroud)

index.html中,您将拥有以下代码:

<?php echo $this->partialLoop('../bar/partial.phtml', $this->paginator);
echo $this->paginator; ?>
Run Code Online (Sandbox Code Playgroud)

问题是您实际上无法使用父遍历,因为我收到此错误:

Requested scripts may not include parent directory traversal ("../", "..\" notation)
Run Code Online (Sandbox Code Playgroud)

有没有办法将部分视图包含在我的内容页面中?(或者我做错了吗?)先谢谢.

pro*_*son 16

您需要传递模块参数:

<?php echo $this->partialLoop('partial.phtml', 'bar', $this->paginator); ?>
Run Code Online (Sandbox Code Playgroud)


Ami*_*arg 7

我经历过同样的问题.我必须将一个模块的视图包含到另一个模块的视图中.我通过在视图的控制器中添加脚本路径来解决了这个问题(我必须在其中包含其他视图)

$this->view->addScriptPath(APPLICATION_PATH.'/modules/moduleName/views/scripts/actionName');
Run Code Online (Sandbox Code Playgroud)

然后在视图文件中包含脚本:

<?php 
    echo $this->render('common-header.phtml');
    //Name of the file you want to include 
?>
Run Code Online (Sandbox Code Playgroud)