1

I have problem in routing in symfony.

I have a function

  public function showresultsAction($product)

that need the object $product to run.

I try to call that Action with the following line:

  $product = $form ->get('product'); 
  return $this->redirect($this->generateUrl('_gs_downloads_product', array(
       'object' => $product)));

When I run my application, I obtain:

 Controller ProductController::showresultsAction()" requires that you provide a value 
 for the "$product" argument (because there is no default value or because there is a 
 non optional argument after this one).

Thank you for your help.

My route definition:

_gs_downloads_product:
    path:  /download/list/product
    defaults: { _controller: AcmeProjectBundle:Product:showresults}  
1
  • Show your route definition Commented Feb 6, 2014 at 20:28

2 Answers 2

1

The issue is with your route definition. the generated url in your case will look like this

"/download/list/product"

change your route to look like this:

_gs_downloads_product:
    path:  /download/list/{product}
    defaults: { _controller: AcmeProjectBundle:Product:showresults}

and your url will look something like this:

"/download/list/12"

assuming that your $product variable is 12

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. Is there a way not to show my object in the URLs? I just need to pass the $product to the action showresults.
As far as I know, there is no built in way in Symfony to do that.
1

Looking at the routing you have not defined the parameter in your route like

_gs_downloads_product:
    path:  /download/list/product/{object}
    defaults: { _controller: AcmeProjectBundle:Product:showresults} 

And then your function will look like

public function showresultsAction($object)

you can also define your parameter as optional or with any default value

_gs_downloads_product:
    path:  /download/list/product/{object}
    defaults: { _controller: AcmeProjectBundle:Product:showresults, object: null} 

or with default value

_gs_downloads_product:
    path:  /download/list/product/{object}
    defaults: { _controller: AcmeProjectBundle:Product:showresults, object: 1} 

Routing

2 Comments

Thank you for your answer. I have two answer, and I ask you the same of the other guy. Is there a way not to show my object in the URLs? I just need to pass the $product to the action showresults.
The entity ids should not be in url best is to have one unique name for each entity i.e for each product you should have the unique slug and pass this slug in the url instead of id and play with it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.