Le 12/02/11 12:24, Wil Moore III a écrit :
The first thing you will want to check when attempting to match a rest route
is whether or not you are trying the correct URI.

For example:

This Uri will likely not match via the rest route:
app.domain.com/<account>/<module>/<controller>/<action>

but based on what I see in your route configuration, the following should
match:
app.domain.com/rest (indexAction)
app.domain.com/rest/id (getAction)
app.domain.com/rest/id/edit (editAction)
app.domain.com/rest/new (newAction)
...

If you want a dynamic<account>  parameter, you'll likely have to chain the
rest route with the hostname route. I don't believe there is a way for the
rest route to match unless the first segment (where you currently have
<account>) corresponds to a module directory.

On the other hand, the default route will look at the first segment, and if
there is no module directory that matches, it will use the default module
and use the first segment as the controller. I am not sure if the rest
router does this as well (I suspect it does but I haven't tested it), but if
it does, you should be able to put your rest controller under your default
module directory to get it to work. If you are having trouble figuring out
how to test this, post back on what you are having trouble with.

BTW, even if the above works, I'm not sure you'll be able to get the name of
the module as it may be replaced by the name of the default module. Again,
I'm not sure so you'll have to test for that.

If none of this works, you may have better luck writing the rest routes from
scratch (means you'll have to manually test for the correct HTTP method).
--
Wil Moore III

Hi Wil and thank you for your extensive reply.

To simplify the problem, I temporarily removed the hostname route. But the 
issue remained.
Let me give you my router configuration:

    $defaultRoute = new Zend_Controller_Router_Route(
        ':account/:module/:controller/:action/*',
        array(
            'account'    => 'demo',
            'module'     => 'default',
            'controller' => 'index',
            'action'     => 'index'
        ),
        array('account' => '[a-z0-9]+')
    );
    $router->addRoute('default', $defaultRoute);

    $restRoute = new Zend_Rest_Route($front, array(), array('rest'));
    $accountRoute = new Zend_Controller_Router_Route(
        ':account',
        array('account' => 'demo'),
        array('account' => '[a-z0-9]+')
    );
    $router->addRoute('rest', $accountRoute->chain($restRoute));

And consider the following URL:
http://app.domain.com/customer1/default/invoice/index

The 'rest' route will be selected first.
'customer1' will properly be identified by the $accountRoute of the chain as 
the account
and 'default' will not match against the value 'rest' of the $restRoute. Up to 
now, everything is fine.

Then, the 'default' route will be selected. But only the subpath 'default/invoice/index' will be passed to it *as the chain consumes the matched part of its child routes* (when they match) and never restore them if a subsequent route doesn't match. Hence the parameters identification will be erroneous.

Won't you consider this a bug? Am I missing something?
--
Guillaume

Reply via email to