2013-03-18 210 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覆蓋幾乎所有情況。