Return html 来自 Zend 中的控制器操作
Return html from controller action in Zend
我有这样的结构:
模块 -> 控制器 -> Amodule -> IndexController
我有一个动作叫做:
public function getTemplateAction(){
... //1) load html file
//2) return html
}
此函数是从 javascript 调用的,通过 url 获取:baseUrl+'/Amodule/index/get-template/viewid/3.
我想根据 return 的 viewid 创建一个 html 模板,我应该把 .html 文件放在哪里,我如何在 Zend 中加载它?我试过了
this->partial('thetemplate.html');
并将 html 文件放在 Amodule 文件夹中,但没有用。
提前致谢!
一个简单的解决方案是将 html 文件放在项目根目录的专用文件夹中,并使用 readfile 输出文件:
public function getTemplateAction() {
readfile(APPLICATION_PATH . '/../templates/thetemplate.html');
exit;
}
在与控制器相同级别的另一个文件夹中添加了它 views/scripts 并在其中创建了部分文件。然后从视图中我将部分加载为:
<?php echo $this->partial('_partialName.phtml', array(
var1 => value1,
var2 => value2
/*... vars to pass in the partial*/
));?>
我有这样的结构:
模块 -> 控制器 -> Amodule -> IndexController
我有一个动作叫做:
public function getTemplateAction(){
... //1) load html file
//2) return html
}
此函数是从 javascript 调用的,通过 url 获取:baseUrl+'/Amodule/index/get-template/viewid/3.
我想根据 return 的 viewid 创建一个 html 模板,我应该把 .html 文件放在哪里,我如何在 Zend 中加载它?我试过了
this->partial('thetemplate.html');
并将 html 文件放在 Amodule 文件夹中,但没有用。 提前致谢!
一个简单的解决方案是将 html 文件放在项目根目录的专用文件夹中,并使用 readfile 输出文件:
public function getTemplateAction() {
readfile(APPLICATION_PATH . '/../templates/thetemplate.html');
exit;
}
在与控制器相同级别的另一个文件夹中添加了它 views/scripts 并在其中创建了部分文件。然后从视图中我将部分加载为:
<?php echo $this->partial('_partialName.phtml', array(
var1 => value1,
var2 => value2
/*... vars to pass in the partial*/
));?>