ZF2 view rendering

◇◆丶佛笑我妖孽 提交于 2020-01-03 05:54:21

问题


In ZF1 I can do something like this:

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

How can I do that in ZF2?


回答1:


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;
    }

Thanks to akrabat for covering almost every scenario.



来源:https://stackoverflow.com/questions/15479262/zf2-view-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!