Wednesday, 28 August 2013

In Symfony2, how to use Multiple Routes in Default Controller

In Symfony2, how to use Multiple Routes in Default Controller

I've been trying to map multiple routes to the default controller, and it
doesn't seem to be working as expected.
I'm using annotations in my controller:
/**
* @Route("/", name="index_controller");
* @Template("SeoSlinkyBundle:Default:index.html.twig");
*/
public indexAction() {}
but I want to do this:
/**
* @Route("/", name="index_controller");
* @Route("/{timeoption}", name="index_controller");
* @Template("SeoSlinkyBundle:Default:index.html.twig");
*/
public indexAction($timeoption = "today") {
echo $today;
exit;
}
That actually works, and if I go to:
http://myapp/hello
The controller echoes "hello"
but if I go to
http://myapp/
The controller should echo "today"
but instead I'm getting this error:
Cannot import resource "/usr/share/www/myapp/src/MyAppBundle/Controller/"
from "/usr/share/www/myapp/app/config/routing.yml".
These are the contents of routing.yml
my_app:
resource: "@MyAppBundle/Controller/"
type: annotation
prefix: /
imag_ldap:
resource: "@IMAGLdapBundle/Resources/config/routing.yml"
Any help would be greatly appreciated!

No comments:

Post a Comment