现在我这样做:
public function indexAction() { ... $view = new viewmodel(array( 'foo' => 'bar',)); return $view; }
问题是我想在$view渲染之后和布局渲染之前做一些事情:
public function indexAction() { ... $view = new viewmodel(array( 'foo' => 'bar',)); $layout = $this->layout(); $layout->content = $view->render(); ... // here I want to do some important action ... $html = $layout->render(); return $this->getResponse()->setContent($html); }
但是没有方法render().在ZF1中,我可以呈现视图:
$view = new Zend_View($data); $html = $view->render($templateName);
我怎么能在ZF2中做到这一点?
试试这个:
原文链接:https://www.f2er.com/php/136367.htmlpublic function IndexAction() { ... $viewRender = $this->getServiceLocator()->get('ViewRenderer'); $html = $viewRender->render($viewmodel); ... }