Is it necessary to have a view file with every controller action

后端 未结 2 1348
名媛妹妹
名媛妹妹 2021-01-24 20:03

Whenever I create a new action in the zend framework controller using the zf CLI tool it creates the corresponding view file. However, I don\'t need the view file for every acti

相关标签:
2条回答
  • 2021-01-24 20:24

    No you don't need to.

    Been a while since i worked with Zend Framework. But if memory serves me well, you have two options here.

    1 - $this->_helper->viewRenderer->setNoRender(true); Which will stop the view being rendered

    2- You can simply do what you need to do and call exit() in the end of the of your action.

    Hope it helps.

    Cheers

    0 讨论(0)
  • 2021-01-24 20:26

    If your action does not require a view then you can disable it:-

    public function myactionAction()
    {
        $this->_helper->layout()->disableLayout();//to disable layout
        $this->_helper->viewRenderer->setNoRender(true);//to disable view
    }
    

    If you want to disable the view/layout for the whole controller then you can put the lines above in the init() method of your controller like this:-

    public function init()
    {
        $this->_helper->layout()->disableLayout();//to disable layout
        $this->_helper->viewRenderer->setNoRender(true);//to disable view
    }
    

    Once you have done that you can safely delete the view files without affecting anything else.

    More details are available in the Action Controller manual.

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