rafi rafi - 12 days ago 13
PHP Question

I am getting "Unable to find the controller for path .... The route is wrongly configured." in Symfony 3

My routing.yml file looks like this

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


And in my HomeController the function the function look like this

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


But when I go to any link, I am getting the error "Unable to find the controller for path "/video/******". The route is wrongly configured."

I am searching Symfony 3 documentation, google, but still no help. Can anyone please help me solve the issue?

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

Here should be _controller, not _contoller :)


HttpKernel:

// 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". The route is wrongly configured.', $request->getPathInfo()));
}

ControllerResolver:

Symfony\Component\HttpKernel\Controller\ControllerResolver.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;
    }
...

In the controller resolver, if the attribute '_controller' does not exist, false is returned. That triggers exception in the Http Kernel.