Zend framework zend framework 3如何在控制器中调用phtml文件

Zend framework zend framework 3如何在控制器中调用phtml文件,zend-framework,Zend Framework,我想在控制器中获取html内容。 为此 任何人都可以帮助获取控制器中的html内容。 谢谢试试这个: public function ajaxAction() { // Turns off the layout and the view $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(tru

我想在控制器中获取html内容。 为此

任何人都可以帮助获取控制器中的html内容。 谢谢

试试这个:

public function ajaxAction() {
        // Turns off the layout and the view
        $this->_helper->layout()->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender(true);

        // Creates a new instance of Zend_View
        $html = new Zend_View();

        // Set a script path for above view
        $html->setScriptPath(APPLICATION_PATH . '/views/scripts/your_custom_path/');

        // Assinging some data to the view
        $html->assign('myVar', $someValue);

        // Renders the view to specified variable
        $responseContent = $html->render('mycontent.phtml');

        echo $responseContent;
}
试试这个:

public function ajaxAction() {
        // Turns off the layout and the view
        $this->_helper->layout()->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender(true);

        // Creates a new instance of Zend_View
        $html = new Zend_View();

        // Set a script path for above view
        $html->setScriptPath(APPLICATION_PATH . '/views/scripts/your_custom_path/');

        // Assinging some data to the view
        $html->assign('myVar', $someValue);

        // Renders the view to specified variable
        $responseContent = $html->render('mycontent.phtml');

        echo $responseContent;
}
“在控制器中获取html内容”的确切含义是什么?您想拥有视图的预定义html内容(phtml文件的内容?您想获得渲染内容(用户看到的内容)?“在控制器中获取html内容”的确切含义是什么?您想拥有视图的预定义html内容(phtml文件的内容?您想获得渲染内容(用户看到的那个)?