How to access custom named views in Zend controllers
-
11-12-2019 - |
Question
How to get access to the custom named views instead of giving the same method name in Zend framework 2.0.
For Eg:
Under index action "return new ViewModel();" will call index.phtml but i want to call an another view here.
Solution
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
OTHER TIPS
Within your controller, you can use the ViewModel
's setTemplate
method to change which script will be rendered:
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
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow