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

时间:2015-07-29 06:13:39

标签: php zend-framework zend-framework2

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

在我的WWWurl_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文件。我想知道他们如何排除这一点。我们需要告诉函数调用特定的视图文件。有一天,我想从xyz.phtml BlaBla functioncontroller function name view file name中的某些different致电{{1}},我该怎么办?那样做。

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

提前致谢!

1 个答案:

答案 0 :(得分:2)

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

  

url_shortener /模块/ MyModuleName /视图/我的模块名/视图/ 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
}