Zend阻止应用程序加载viewscript

时间:2012-06-20 00:59:57

标签: zend-framework

如何阻止应用程序使用任何参数呈现视图。

所以,如果我有一些东西

www.mywebsite.com/myapplication/mycontroller/some/params

如何阻止它,这样无论控制器后面发生什么,它都不会加载视图脚本。我已经能够在行动中做到这一点,但我想为所有行动做到这一点。

2 个答案:

答案 0 :(得分:2)

默认情况下,前端控制器启用ViewRenderer操作助手。该帮助程序负责将视图对象注入控制器,以及自动呈现视图。您可以通过以下方法之一在操作控制器中禁用它:

class FooController extends Zend_Controller_Action
{
    public function init()
    {
        // Local to this controller only; affects all actions,
        // as loaded in init:
        $this->_helper->viewRenderer->setNoRender(true);

        // Globally:
        $this->_helper->removeHelper('viewRenderer');

        // Also globally, but would need to be in conjunction with the
        // local version in order to propagate for this controller:
        Zend_Controller_Front::getInstance()
            ->setParam('noViewRenderer', true);
    }
}

参考:http://framework.zend.com/manual/en/zend.controller.action.html

答案 1 :(得分:0)

这是我必须做的才能让它做我想做的事情:

    public function preDispatch(){
        if($this->User->isValid()){
            if($this->getRequest()->getActionName() !== 'login' ){ 
                    $this->_forward('login');
            }
         }
    }

    public function loginAction(){
        $this->_helper->FlashMessenger('You must be logged in to do that!');
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->view->messages = $this->_flashMessenger->getMessages();
        $this->_helper->viewRenderer->setNoRender(false);
    }