在 ZF2 中禁用视图 [英] disabling view with in action in ZF2
本文介绍了在 ZF2 中禁用视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力禁用 ZF2 中的视图 $this->_helper->viewRenderer->setNoRender();或 (true)
没有运气,因为它总是说那里
I am struggling with disabling view in ZF2 $this->_helper->viewRenderer->setNoRender(); or (true)
with no luck as it always says there
PHP Fatal error: Call to a member function setNoRender() on a non-object in ../module/Location/src/Location/Controller/LocationController.php on line 190
推荐答案
要完全禁用视图,从控制器操作中,您应该返回一个 Response 对象:
To disable the view completely, from within a controller action, you should return a Response object:
<?php
namespace SomeModule\Controller;
use Zend\Mvc\Controller\ActionController,
Zend\View\Model\ViewModel;
class SomeController extends ActionController
{
public function someAction()
{
$response = $this->getResponse();
$response->setStatusCode(200);
$response->setContent("Hello World");
return $response;
}
}
要禁用布局并仅呈现此操作的视图模型模板,您可以这样做:
To disable the layout and just render this action's view model template you would do this:
public function anotherAction()
{
$result = new ViewModel();
$result->setTerminal(true);
return $result;
}
这篇关于在 ZF2 中禁用视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文