ZF2视图渲染

时间:2013-03-18 14:29:22

标签: zend-framework2

在ZF1中,我可以这样做:

$view = new Zend_View();
$view->setScriptPath($viewDir);
$html = $view->render('template_name.phtml');

我怎样才能在ZF2中做到这一点?

1 个答案:

答案 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几乎覆盖了所有情景。