简体   繁体   English

如何在Zend控制器中访问自定义命名视图

[英]How to access custom named views in Zend controllers

How to get access to the custom named views instead of giving the same method name in Zend framework 2.0. 如何访问自定义命名视图,而不是在Zend Framework 2.0中提供相同的方法名称。

For Eg: 例如:

Under index action "return new ViewModel();" 在索引操作下“返回新的ViewModel();” will call index.phtml but i want to call an another view here. 将调用index.phtml但我想在这里调用另一个视图。

Just call model view with view you want: 只需使用所需的视图调用模型视图:

     $model = new ViewModel(); 
     $model->setTemplate('edit'); 
     return $model;

More info: http://framework.zend.com/manual/2.0/en/modules/zend.view.renderer.php-renderer.html 更多信息: http : //framework.zend.com/manual/2.0/en/modules/zend.view.renderer.php-renderer.html

Within your controller, you can use the ViewModel 's setTemplate method to change which script will be rendered: 在您的控制器内,您可以使用ViewModelsetTemplate方法来更改将呈现的脚本:

public function someAction()
{
    // do stuff here

    $viewModel = new ViewModel($anArrayOfVariablesForTheView);
    $viewModel->setTemplate('application/view/arbitrary');
    return $viewModel;
}

Note that you don't need to specify the .phtml . 请注意,您无需指定.phtml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM