Two optional variables in Symfony2 routing

When I try to use 2 optional variables in Symfony2 routing I have th error: No route found for "GET /" In routing.yml I have:

pattern:  /{page}/{ads_on_page}/
defaults: { _controller: AcmeAshavatBundle:Page:index, page:1, ads_on_page:2 }
   _method:  GET|POST

And when i go to http://localhost:8080/AshavatSy/web/app_dev.php/ I have the error. The intresting is that if I run http://localhost:8080/AshavatSy/web/app_dev.php/1 it works well.Also, if I change the path to pattern: /main/{page}/{ads_on_page}/ it works well. What is the problem? I'd like to ask, that someone will try to do like this [e.g. pattern: /a/b/ defaults: {... a:1,b:2}, or as he thinks you should do it] in his project, and see is it a common problem...


I think you forgot to pass these two arguments to your IndexAction() in controller.

Try this code

Public function indexAction($page,$ads_on_page)

Hope this helps you.

I managed to have something similar working by defining two routes, pointing to the same controller, using default parameters. In my case, using annotations:

 * @Route("/products/{catId}/{prodId}", defaults={"catId"="", "prodId"=""})
 * @Route("/products/")
 * @Template()
public function indexAction($catId = null, $prodId = null) {

I think that using default parameters only, Symfony would expect two /.


Need Your Help

Should any domain object, not be serializable?

c# .net-3.5 serialization c#-3.0

Is there a way to just tell the compiler, that I want my objects to be serializable by default?

How does =~ behave in Perl?

regex perl

I have the following perl script: