Symfony2如何在不扩展控制器解析器的情况下找到正确的控制器


How does Symfony2 find the correct controller without extending the ControllerResolver?

我一直在看Symfony2代码,我无法弄清楚它如何在不扩展/覆盖ControllerResolver类的功能的情况下找出要使用的正确控制器。我不认为默认的控制器解析器能够找到类似 BundleName:Bundle:action 到控制器的控制器。

控制器在 HTTPKernel 类 (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/HttpKernel.php) 中解析。这就是那里发生的事情

    // load controller
    if (false === $controller = $this->resolver->getController($request)) {
        throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". Maybe you forgot to add the matching route in your routing configuration?', $request->getPathInfo()));
    }

一旦控制器被解析,控制器类将出现在请求的__controller属性中

相关文章: