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

前端 未结 2 1891
小鲜肉
小鲜肉 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:43

    Try this:

    public function IndexAction()
    {
        ...
        $viewRender = $this->getServiceLocator()->get('ViewRenderer');
        $html = $viewRender->render($viewModel);
        ...
    }
    

提交回复
热议问题