我想使用一些ajax,但我不知道如何使用与zend framework 2中的setNoRender()相同的函数来禁用渲染视图。
如何在zend framework 2中禁用渲染视图?
发布于 2012-09-09 02:08:00
如果您使用的是JSON,那么查看视图的JsonStrategy
并从控制器返回一个JsonModel
。请参阅此article。
或者,你可以从你的控制器返回一个Response
,跳过整个视图层:
public function testAction()
{
$response = $this->getResponse();
$response->setStatusCode(200);
$response->setContent('foo');
return $response;
}
发布于 2012-12-05 05:18:03
我找到了一些答案。
虽然$this->layout()->getLayout()
返回新选择的布局的名称/路径...布局不会因以下任何命令而改变...
在控制器中
$this->getLocator()->get('view')->layout()->setLayout('layouts/ajax.phtml');
$this->getLocator()->get('view')->layout()->setLayout('ajax');
$this->getLocator()->get('view')->layout()->disableLayout();
在视图PHTML文件中
$this->layout()->setLayout('layouts/ajax.phtml');
$this->layout()->setLayout('ajax');
$this->layout()->disableLayout();
发布于 2012-10-22 05:42:13
$view =新建视图();$ViewModel->setTerminate(True);
https://stackoverflow.com/questions/12332843
复制相似问题