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

前端 未结 2 1334
北荒
北荒 2021-02-09 07:15

Now I am doing so:

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

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-09 07:41

    Try this:

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

提交回复
热议问题