-1

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

所以如果我有什么是

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

我怎样才能停止它,这样无论控制器之后发生什么,它都不会加载视图脚本。我已经能够在动作中做到这一点,但我想对所有动作都这样做。

4

2 回答 2

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

于 2012-06-20T09:44:37.113 回答
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);
    }
于 2012-06-22T04:57:20.017 回答