1
votes

I'm using url_for('module/myaction/id/3') to create links in modified admin generator screens. Whenever I make a new action and try to link to it with url_for ('module/action/id/3'), I get /module/myaction/action.

When I try url_for('module/3/myaction') i get the same result.

However when I use url_for('module/myaction?id=3') I get the expected result: module/3/myaction

I have only the default admin generated routing rules in my routing file.

Is this behaviour expected?

1

1 Answers

6
votes

Yes it is expected... In the sense that is expected that passing in an external URL will produce unexpected results.

You should be passing an internal uri to url_for an internal URI is written in the form:

@route_name?param=value

moduleName/actionName?param=value

You can also represent the arguments for an internal url separately by using a route name and an object (if its a object route or route collection) in these cases it would look like:

url_for('route_name', params);

Where params is either the object expected by the route (normally a Doctrine or Propel model instance) or an array of parameters.

These internal URI's are then converted to the external url by the routing system. You are getting incorrect results because you are trying to pass in the external URL, which doesnt make sense because if you know the url then there is no reason to route it :-)