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:

AcmeAshavatBundle_homepage:
pattern:  /{page}/{ads_on_page}/
defaults: { _controller: AcmeAshavatBundle:Page:index, page:1, ads_on_page:2 }
requirements:
   _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...

Answers


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 /.

HTH


Need Your Help

Exporting to a exe with jarsplice

java jar export exe lwjgl

I am making a game using lwjgl, and am trying to figure out how to export it into a single runnable jar or exe.

How do you find the sum of all the numbers in an array in Java?

java arrays sum

I'm having a problem finding the sum of all of the integers in an array in Java. I cannot find any useful method in the Math class for this.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.