duankeng2026 2012-03-11 00:41
浏览 34
已采纳

setDispatched()澄清

The question is about the router's setDispatched() method of Zend Framework...

I have a fooAction() and a loginAction() in the same controller (the indexController).

I also have an ActionHelper and I'm using it's preDispatch() method. At the end of this function I have an if statement where I check the ACL:

public function preDispatch() {

    // some code...

    if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
        $request->setModuleName('default');
        $request->setControllerName('index');
        $request->setActionName('login');

        $request->setDispatched(false); //what does this mean exactly??
    }
}

So when I want to reach fooAction(), and the user hasn't got the permission, I set the Action name to 'login'...

Now my question is: what does the $request->setDispatched(false); mean exactly?

Does it indicate that ZF can start to dispatch the loginAction() because it hasn't been dispatched yet (setDispatched(false);)?

  • 写回答

1条回答 默认 最新

  • doufei4418 2012-03-11 00:52
    关注

    From Zend Framework's Reference Guide:

    At the beginning of each iteration, it sets a flag in the request object indicating that the action has been dispatched. If an action or pre or postDispatch plugin resets that flag, the dispatch loop will continue and attempt to dispatch the new request. By changing the controller and/or action in the request and resetting the dispatched flag, the developer may define a chain of requests to perform.

    By calling setDispatched(false) you're basically saying that the request wasn't sent to the controller yet, and the Dispatcher will attempt to re-despatch it. This is necessary because you're changing the module, controller and action of the request and you want the Dispatcher to process it again and send it to the right place.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败