zend-framework - zend framework 3 如何在控制器中调用 phtml 文件
问题描述
我想在控制器中获取 html 内容。为了这
public function posteemailAction(){
$view=$this->render("auth-acl/email/_getemail.phtml");
print_r($view);die;
}
任何人都可以帮助在控制器中获取 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;
}
推荐阅读
- javascript - Vuetify:工具提示不适用于自定义组件
- cordova - Ms ADAL login whith the same token apps Ionic 4
- groovy - 如何使用 groovy 从 DataSource 中删除重复项
- linux - Linux CLI 监视开关 -e,--errexit 意外退出,带有“非零状态的命令退出,按一个键退出”
- javascript - Wordpress AJAX 调用总是返回 0
- extjs - Extjs - 如果通过绑定计算,是否可以将 column.hidden 重置为初始状态?
- c# - Blazor/Blazorise.Bootstrap html 元素在使用组件的多个实例时进行交互
- csvhelper - CSV Helper 将字符串转换为日期时间
- python - Tkinter 在未聚焦时选择了 Entry() 和 Spinbox() 字段文本背景和前景
- laravel - 如何将此查询转换为 Eloquent 或查询生成器?