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

后端 未结 2 1352
名媛妹妹
名媛妹妹 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: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.

提交回复
热议问题