在ZF1中,我可以这样做:
$view = new Zend_View();
$view->setScriptPath($viewDir);
$html = $view->render('template_name.phtml');
我怎样才能在ZF2中做到这一点?
答案 0 :(得分:2)
public function abcAction()
{
$view = new ViewModel(array('variable'=>$value));
$view->setTemplate('module/controler/action.phtml'); // path to phtml file under view folder
return $view;
}
public function differentViewScriptAction()
{
// Use a different view script
$viewModel = new ViewModel();
$viewModel->setTemplate('application/view/arbitrary');
return $viewModel;
}
感谢akrabat几乎覆盖了所有情景。