从 Zend Framework2 中的操作调用另一个视图

Calling another view from an action in Zend Framework2

我已经从 github 下载了一个示例 ZF2 项目并在我的系统中进行了配置。我无法理解路由系统,他们如何从操作中调用视图,以及我应该如何从我的控制器 aAction 函数中调用其他视图(b.phtml

在我的 WWW url_shortner\module\Application\src\Application\Controller\IndexController.php 是我的索引控制器

在我的IndexController.php我的索引函数是这样的

public function indexAction()
{ 
}

函数是空的

里面有视图文件
url_shortner\module\Application\view\application\index\index.phtml

在索引函数中没有调用 index.phtml 但仍在加载 index.phtml 文件。我想知道他们是如何解决这个问题的。我们需要告诉函数调用特定视图文件的地方。有一天,我想从 controller 中的某些 BlaBla function 调用 xyz.phtml,其中 function nameview file namedifferent,我怎么能这样做。

如果你想要任何其他代码,请问我。我会把代码放在这里 我真的很挣扎。请帮助我。

提前致谢!

如果您在控制器中未定义任何内容,则这是默认视图位置

url_shortener/module/MyModuleName/view/my-module-name/view/CONTROLLER_NAME/ACTION_NAME.phtml

您可以这样改变您的看法:

public function indexAction(){
    $view = new \Zend\View\Model\ViewModel();
    $view ->setTemplate('your-module/your-controller/your-view'); //without .phtml
    return $view
}