-- Cameron <[email protected]> wrote
(on Wednesday, 09 September 2009, 05:35 PM +0800):
> Hi, this is very likely to be a dumb question, but I'd really like to have my
> controllers respond to "normal" requests (as in http://domain.com/product/
> display/id/1) and also the full range of RESTful requests (GET http://
> domain.com/product/1 and so on). Turning on Zend_Rest_Route across all my
> controllers breaks regular requests, but does make them respond correctly to
> REST, but yeah... I know this is unlikely to work, I was just wondering if
> there's a way of somehow ordering the routes so that if regular ones don't
> match then use the RESTful ones or something. Failing that, I suppose I'm just
> going to have to come up with a nice clean way to link the separate REST
> controllers back to the "normal" code.
You can do it in a variety of ways. First, you can always use the
default route in conjunction with the Rest route, though you run the
risk of the actions being interpreted as IDs.
Another option is to create an additional Zend_Controller_Router_Route
instance that matches your controller:
$route = new Zend_Controller_Router_Route(
'product/:action/*',
array(
'controller' => 'product',
),
array(
'action' => '^[a-z][a-z0-9.-]+',
)
);
Assuming your IDs are numeric, the above will not match unless the
action starts with an alphabetic character -- which should be safe for
your purposes. (You can also use static and regexp routes in this
fashion.)
If you use such a route, make sure you register it *after* the REST
route to ensure it's executed *before* it.
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/