I encountered a problem, have the following:
DefaultController with a simple action:
/**
* @Route("/register")
* @Template
*/
public function indexAction() {
$oForm = $this->createForm(new RegisterType());
return array(
'form' => $oForm->createView()
);
}
In my twig template I try to use:
<form action="{{ path('register') }}" method="post"></form>
But I get the following error:
An exception has been thrown during the rendering of a template ("Route "register" does not exist.") in EBTSCustomerBundle:Default:index.html.twig at line 2.
When I explicitely define a “register” route in app/config/routing.yml:
register:
pattern: /register
defaults: { _controller: EBTSCustomerBundle:Controller:Default:index }
Then it works fine. Can’t find any reasonable docs about it, I thought that routes defined via annotations should be visible in the whole application.
Any ideas guys?
Routes by annotations still need to be imported into routing.yml as so:
This will tell the routing to scan the
Controllerdirectory of theAcme\HelloBundleand import all routes.You can find more information about routing with annotations here. That link will also tell you how to activate routes as I have shown above.
Also, I noticed that your route annotation needs the
nameparameter to be accessible throughregisterusing thepathfunction otherwise it’d be accessed throughacme_bundlename_controllername_actionname:Hope that helps!