Description

The assemble() method in Zend_Rest_Route can not create a url for the "new" action. Instead, it provides a link to the index action ("/products" instead of "/products/new"). This is not the same as the match() method which makes allowances for the "index" and "new" actions.

This may also be the root issue behind ZF-7753. Included patch is against trunk.

The fix is small, but it may create a (very small) BC-break/bug if the $params['index'] is also set as this also tries to generate a url for the index action. That said, the $params['index'] behavior may be a bug that should instead become $params['action] == 'index'. Please let me know if I should file this under another ticket.

The TRUE constant is only needed so that some positive (evaluates to true) value is given. The Zend_Rest_Route#assemble method
will find 'index' to be set and it's value evaluates to true (so 1 or '1' or true would work equally well as it doesn't check for === TRUE). The 'index' value is this removed from the parameters array and the remaining parameters (id, key) are added to the resulting URL string.

'action' has already been removed from the parameters array by this point so it will not accidentally be added to the string.

Having 'index' => true also negates having 'action' => 'edit' or 'action' => 'new'. In other words, if 'index' => true, then 'action' is ignored.

FYI, removed old diffs after getting the original poster's permission to do so.

Posted by Ross Tuck (rosstuck) on 2010-07-07T13:34:05.000+0000

The BC-break only occured (as I recall) with the now removed patches. Your newer patch fixes a few more things and does not suffer from the same problem. All good. :)

However, my main question about the index key was exactly what you point out. Why does it search for "index" => true, and not "action" => "index" like all other routes do? If I pass in array("action" => "edit", "index" => true), I expect it not to ignore action but instead treat index as a named parameter.