我在Symfony 3中得到了"Unable to find the controller for path .... The route is wrongly configured."



我的路由文件看起来像

video:
  path: /video/{utubeURL}
  defaults: {_contoller: SOMEHomeBundle:Home:video}

和我的homecontroller函数函数看起来像这样:

public function videoAction($utubeURL)
{
    $this->data['cssFiles'] = [*********];
    $this->data['utubeURL'] = $utubeURL;
    return $this->render('SOMEHomeBundle:Default:video.html.twig', $this->data);
}

但是,当我转到任何链接时,我会遇到错误"无法找到路径的控制器"/video/******&quort。该路线被错误配置。&quot'

我正在搜索Symfony 3文档和搜索引擎,但仍然没有解决方案。我该如何解决问题?

...
  defaults: {_contoller: SOMEHomeBundle:Home:video}

这里应该是_controller,而不是_contoller:)


httpkernel:

// SymfonyComponentHttpKernelHttpKernel.php
// load controller
if (false === $controller = $this->resolver->getController($request)) {
    throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". The route is wrongly configured.', $request->getPathInfo()));
}

ControlerResolver:

SymfonyComponentHttpKernelControllerControllerResolver.php
/**
 * {@inheritdoc}
 *
 * This method looks for a '_controller' request attribute that represents
 * the controller name (a string like ClassName::MethodName).
 */
public function getController(Request $request)
{
    if (!$controller = $request->attributes->get('_controller')) {
        if (null !== $this->logger) {
            $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.');
        }
        return false;
    }
...

在控制器解析器中,如果属性" _controller"不存在,则返回false。这会触发HTTP内核中的异常。

最新更新