I'm working on Symfony 2.3 and I declared a new route and new controller, but when I call this controller from the browser I get this error:
The controller for URI "/user/1" is not callable. in /dev.mydomain.org/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php at line 82
This is my simple route configuration:
user_homepage:
pattern: /user
defaults: { _controller: UserBundle:Default:index }
user_show:
pattern: /user/{id}
defaults: { _controller: UserBundle:Default:show }
requirements:
id: \d+
And this is my very simple controller:
public function showUserAction($id)
{
return $this->render('UserBundle:Default:show.html.twig', array());
}
What is wrong?
Not the case here. But there is another related issue:
If you forget the 'Action' suffix all will work. But when you realized that you forget the suffix and then add it ... surprise! Same error as the OP.
The problem here is about caching
Symfony creates two file for caching urls:
If you change your action name (i.e. adding 'Action' suffix) then that cache info is obsolete.
Solution
I would like to share my experience & how I solved it:
I was importing one bundle in an application whose routes were defined using annotations and they were importing fine in application too by using:
But since my bundle controllers were defined using services, Symfony was showing error:
I updated my bundle for routing to use routing.yaml file over annotations and referring to controllers as
service::method
syntax and then this error is gone.Bundle routes must be imported using
Hope this will save someone's time.
Similar to the accepted answer, if your controller is defined as a service, e.g. (in YAML):
And your route uses this controller service:
Then it's necessary to name the action method in full including the
Action
suffix, otherwise you will get the "controller ... is not callable" error.