Can I render view without returning it in action controller in zend framework 2?

前端 未结 2 1798
小鲜肉
小鲜肉 2021-02-09 07:28

Now I am doing so:

public function indexAction() {
    ...
    $view = new ViewModel(array(
        \'foo\' => \'bar\',
    ));
    return $view;
}

2条回答
  •  情话喂你
    2021-02-09 07:42

    Complementing the answer, with layout included...

    public function IndexAction() {
        ...
        $viewRender = $this->getServiceLocator()->get('ViewRenderer');
    
        $layout = new ViewModel();
        $layout->setTemplate("layout/main");
        $layout->setVariable("content", $viewRender->render($viewModel));
    
        $html = $viewRender->render($layout);
        ...
    }
    

提交回复
热议问题