Zend_Rest_Route(日本語) Zend_Restコンポーネントは、 Zend_Controller_Router_RewriteのためにRESTfulなルートを含みます。 このルートは、HTTPメソッド及びURIをモジュール、 コントローラ及びアクションに変換することにより、 リクエストを割り振る標準化されたルーティング機構を提供します。 下表では、リクエスト・メソッドとURIを割り振る方法の概要を提示します。 Zend_Rest_Route Behavior メソッド 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 利用法 Zend_Rest_Routeをアプリケーション全てで有効にするには、 構成パラメータ無しで構築して、フロントコントローラにデフォルトのルートとして追加してください。 getRouter()->addRoute('default', $restRoute); ]]> もしZend_Rest_Routeが有効なモジュール、 コントローラまたはアクションにマッチできなければ、FALSEを返します。 そして、ルータはルータのなかの次のルートを使ってマッチを試みます。 特定のモジュールでZend_Rest_Routeを有効にするには、 コンストラクタの3番目の引数としてモジュール名の配列を使って構成します。 getRouter()->addRoute('rest', $restRoute); ]]> 特定のコントローラでZend_Rest_Routeを有効にするには、 コントローラ名の配列を各モジュールの配列の要素の値として追加します。 array('ratings') )); $front->getRouter()->addRoute('rest', $restRoute); ]]> Zend_Rest_Route with Zend_Config_Ini INI 構成ファイルから Zend_Rest_Route を使うには、 ルート型のパラメータを使用して、構成オプションを設定します。 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. そして、Rewrite ルータ・オブジェクトの addConfig() メソッドを使います。 addConfig($config, 'routes'); ]]> Zend_Rest_Controller Zend_Rest_Routeを使う コントローラの開発を助けるか誘導するためには、 Zend_Rest_Controllerからコントローラを拡張してください。 Zend_Rest_Controllerでは、 RESTfulなリソースのために5つの最も一般的に必要とされる操作を 抽象的なアクション・メソッドの形で定義します。 indexAction() - リソースのインデックスを取得して、それをビューに割り当てます。 getAction() - URIで識別される単一のリソースを取得して、それをビューに割り当てます。 postAction() - 単一の新しいリソースを受け取って、その状態を持続します。 putAction() - URIで識別される単一のリソースを受け取って、その状態を持続します。 deleteAction() - URIで識別される単一のリソースを削除します。