0
votes

I need to use my route site_edit with an extra query parameter 'company'=1. The route is as follows:

@Route("/_sys/site/edit/{id}", name="site_edit", defaults={"id"=null})

Symfony2 generates the link /_sys/site/edit?comp=1 which looks fine for me. It hits the action alright but Request#query is empty though $_GET is array('comp'=>'1'). If I adjust the query string to be /_sys/site/edit/?comp=1 then no matching route is found. If I insert some value for {id} e.g. /_sys/site/edit/new?comp=1 then all is fine ($id="new" and Request#query is array('comp'=>'1') but this case is not tolerable by application logic I must not change.

I need a route with very similar structure where exactly one of the parameters comp and id is present. So the urls need to be generated as [twig] url('site_edit', {'id':positiveInteger}) or url('site_edit', {'comp':positiveInteger}).

Is this a bug? IMHO in /_sys/site/edit?comp=1 the part before ? should launch the action with {id}=null (ok) and the part after ? should ensure that Request#query-get('comp') yields '1' (fail).

1

1 Answers

0
votes

What about

@Route("/_sys/site/edit/{id}/comp/{comp}", name="site_edit", 
        defaults={"id"=null})

You can assign a default value to comp, to treat it as emtpy if you wish.