disabling view with in action in ZF2

前端 未结 9 609
滥情空心
滥情空心 2020-12-24 03:10

I am struggling with disabling view in ZF2 $this->_helper->viewRenderer->setNoRender(); or (true) with no luck as it always says there



        
相关标签:
9条回答
  • 2020-12-24 03:47

    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;
    
    0 讨论(0)
  • 2020-12-24 03:49

    Just return '' in the Method and it will not autoload the View template

    public function goAction()
    {   
        return '';
    }
    
    0 讨论(0)
  • 2020-12-24 03:50
    public function testAction()
    {   
        return false;
    }
    

    simply return false.

    0 讨论(0)
提交回复
热议问题