首页 > 解决方案 > zend framework 3 如何在控制器中调用 phtml 文件

问题描述

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

public function posteemailAction(){
  $view=$this->render("auth-acl/email/_getemail.phtml");
   print_r($view);die;

}

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

标签: zend-framework

解决方案


尝试这个:

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

推荐阅读