【问题标题】:Phalcon PHP: Dispatcher's `forward` function does not workPhalcon PHP:调度程序的“转发”功能不起作用
【发布时间】:2018-08-09 12:19:44
【问题描述】:

在我的CustomerclientController 中的reentryAction 内,我想转发到indexAction,以防发布参数的有效性检查成功。

不幸的是,前锋不起作用。在调试时,我确定将再次调用reentryAction 方法,而不是indexAction。

我在services.php 中注册了一个 Dispatcher,如下所示:

$di->setShared('dispatcher', function() use ($eventsManager) {

    $dispatcher = new MvcDispatcher();
    // Bind the eventsManager to the view component
    $dispatcher->setEventsManager($eventsManager);
    return $dispatcher;
});

客户客户端控制器:

class CustomerclientController extends Controller {
    public function reentryAction($hash) {
        // ... a lot of code
        if ($this->request->isPost()) {
            // ... a lot of code
            if ($valid) {
                $this->dispatcher->forward([
                    "customerclient",
                    "index"
                ]);
                return;
            }
        }
    }
    public function indexAction() {
        //Does something wise
    }
}

我没有定义特殊的路线,也没有使用route.php 文件。

我做错了什么或忘记了什么?

提前感谢您的帮助!

【问题讨论】:

    标签: php model-view-controller php-7 phalcon phalcon-routing


    【解决方案1】:

    您确定需要使用 MvcDispatcher 吗? 我检查了我的项目,我正在使用 Dispatcher

    $di->set('dispatcher', function() use ($di) {
        $dispatcher = new Dispatcher;
        $dispatcher->setEventsManager($eventsManager);
        return $dispatcher;
    }); 
    

    我希望它有效!

    【讨论】:

    • 感谢您的回答。我想这不是问题所在。我在services.php 之上使用use \Phalcon\Mvc\Dispatcher as MvcDispatcher
    • 我将在周一更深入地探讨这个问题。
    【解决方案2】:

    首先,尝试返回dispatcher->forward()。其次,也许将键写在数组中。

    if ($valid) 
      return $this->dispatcher->forward([
        "controller" => "customerclient",
        "action" => "index"
      ]);
    

    希望有帮助!

    【讨论】:

    • 感谢您的快速回答。我尝试了您的方法,但不幸的是出现了同样的问题。
    • 还有其他想法吗?
    • 说实话没什么。你的 $valid 返回 true 吗?
    猜你喜欢
    • 1970-01-01
    • 2018-04-14
    • 2019-01-21
    • 1970-01-01
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    相关资源
    最近更新 更多