首页 > 解决方案 > Phalcon PHP:调度程序的“转发”功能不起作用

问题描述

reentryActionCustomerclientController想转发到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文件。

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

在此先感谢您的帮助!

标签: phpmodel-view-controllerphp-7phalconphalcon-routing

解决方案


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

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

希望有帮助!


推荐阅读