Zend_Rest_Route The Zend_Rest component contains a RESTful route for Zend_Controller_Router_Rewrite. This route offers a standardized routing scheme that routes requests by translating the HTTP method and the URI to a module, controller, and action. The table below provides an overview of how request methods and URI's are routed. Zend_Rest_Route Behavior Method URI Module_Controller::action GET /product/ratings/ Product_RatingsController::indexAction() GET /product/ratings/:id Product_RatingsController::getAction() POST /product/ratings Product_RatingsController::postAction() PUT /product/ratings/:id Product_RatingsController::putAction() DELETE /product/ratings/:id Product_RatingsController::deleteAction() POST /product/ratings/:id?_method=PUT Product_RatingsController::putAction() POST /product/ratings/:id?_method=DELETE Product_RatingsController::deleteAction()
Zend_Rest_Route Usage To enable Zend_Rest_Route for an entire application, construct it with no config params and add it as the default route on the front controller: getRouter()->addRoute('default', $restRoute); ]]> If Zend_Rest_Route cannot match a valid module, controller, or action, it will return FALSE and the router will attempt to match using the next route in the router. To enable Zend_Rest_Route for specific modules, construct it with an array of module names as the 3rd constructor argument: getRouter()->addRoute('rest', $restRoute); ]]> To enable Zend_Rest_Route for specific controllers, add an array of controller names as the value of each module array element. array('ratings') )); $front->getRouter()->addRoute('rest', $restRoute); ]]> Zend_Rest_Route with Zend_Config_Ini To use Zend_Rest_Route from an INI config file, use a route type parameter and set the config options: The 'type' option designates the RESTful routing config type. The 'defaults' option is used to specify custom default module, controller, and/or actions for the route. All other options in the config group are treated as RESTful module names, and their values are RESTful controller names. The example config defines Mod_ProjectController and Mod_UserController as RESTful controllers. Then use the addConfig() method of the Rewrite router object: addConfig($config, 'routes'); ]]> Zend_Rest_Controller To help or guide development of Controllers for use with Zend_Rest_Route, extend your Controllers from Zend_Rest_Controller. Zend_Rest_Controller defines the 5 most-commonly needed operations for RESTful resources in the form of abstract action methods. indexAction() - Should retrieve an index of resources and assign it to view. getAction() - Should retrieve a single resource identified by URI and assign it to view. postAction() - Should accept a new single resource and persist its state. putAction() - Should accept a single resource idenitifed by URI and persist its state. deleteAction() - Should delete a single resource identified by URI.