对于Zend框架项目,哪种模型最好呈现html代码?模型或控制器(如果无法在视图中完成,例如,假设我们有一个ajax请求)
我认为您仍然可以使用Zend_View。如果您需要通过AJAX请求获取某些内容,只需将其呈现在控制器中,然后将其作为响应传递(通过简单的回显)即可。例子:
// controller body
public function ajaxAction()
{
// turn off the layout and view
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
// create new instance of Zend_View
$html = new Zend_View();
// set script path for above view
$html->setScriptPath(APPLICATION_PATH . '/views/scripts/_custom/');
// assing some data to view
$html->assign('myVar', $someValue);
// render view to specified variable
$responseContent = $html->render('mycontent.phtml');
echo $responseContent;
}
现在像其他视图一样创建application / view / scripts / _custom / mycontent.phtml脚本,以适应您的需求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句