2013-03-18 168 views
0

在ZF1我可以做这样的事情:ZF2视图渲染

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

我如何能做到这一点在ZF2?

回答

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覆盖几乎所有情况。