I am struggling with disabling view in ZF2 $this->_helper->viewRenderer->setNoRender(); or (true)
with no luck as it always says there
You can do so using the console model, or kill execution arbitrarily.
<?php
namespace SomeModule\Controller;
use Zend\Mvc\Controller\ActionController;
use Zend\View\Model\ConsoleModel; // if use ConsoleMode
use Zend\View\Model\JsonModel; // if use JSON
class SomeController extends ActionController
{
public function someAction() {
return new ConsoleModel(array(
'message' => 'Hello World',
));
}
// Json Method
public function jsonAction() {
return new JsonModel(array(
'message' => 'Hello World',
));
}
// This is really exaggerated, but it is quite effective.
public function killAction() {
echo 'Hello World';
exit;
}
}
In view use: some.phtml
<?php
echo $message;
json.phtml
<?php
echo $message;
Just return '' in the Method and it will not autoload the View template
public function goAction()
{
return '';
}
public function testAction()
{
return false;
}
simply return false.