If you have something like this:
/**
* !Route GET, post/
* !Route GET, post/$id/
**/
function post($id = 0) {}
Url::action("Controller::post",1) will work just fine.
Url::action("Controller::post") won't work (you would expect otherwise) and gives an error.
If you reverse the order of annotations, the Url::action("Controller::post") will work and
Url::action("Controller::post",1) won't give any errors, but gives /post/ as url, instead of /post/1/.
The function does not work fine with methods that have multiple annotations. This is caused by the fact that urlTo gets its Url by reading out Controller::methodUrls which only contains the url specified by the last annotation, instead of an array of all urls.
Is this a true bug or am I using the annotations in a wrong way?
I can tell you how I think it should behave...
Routes ought to be evaluated from first to last searching for an appropriate match given the number of variables passed to urlTo.
Currently the router assumes one route per method, so making this change would probably have some fairly far-reaching consequences. For the time being, I suggest working around it by creating a new method as a wrapper for post()
/**
* !Route GET, post/
**/
function postIndex() {
return $this->post();
}
/**
* !Route GET, post/$id/
**/
function post($id = 0) {}
Some other things I would like to see...
Named routes
/**
* !Route GET, post/, postIndex
* !Route GET, post/$id/
**/
to allow for calls like Url::to('postIndex')
Alternative syntax for passing variables to routes as parameters
$controller->urlTo("details?id=43")
It feels cleaner to me. I think I picked it up from Rails. I implemented this on my fork, but it's ignoring the key (id)