Zend_Controller-Router-Route-Rest.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 24249 -->
  4. <sect3 id="zend.controller.router.routes.rest">
  5. <title>Zend_Rest_Route(日本語)</title>
  6. <para>
  7. <classname>Zend_Rest</classname>コンポーネントは、
  8. <classname>Zend_Controller_Router_Rewrite</classname>のためにRESTfulなルートを含みます。
  9. このルートは、<acronym>HTTP</acronym>メソッド及び<acronym>URI</acronym>をモジュール、
  10. コントローラ及びアクションに変換することにより、
  11. リクエストを割り振る標準化されたルーティング機構を提供します。
  12. 下表では、リクエスト・メソッドと<acronym>URI</acronym>を割り振る方法の概要を提示します。
  13. </para>
  14. <table frame="all">
  15. <title>Zend_Rest_Route Behavior</title>
  16. <tgroup cols='3' align='left' colsep='1' rowsep='1'>
  17. <colspec colname='method' />
  18. <colspec colname='URI' />
  19. <colspec colname='route' />
  20. <thead>
  21. <row>
  22. <entry>メソッド</entry>
  23. <entry><acronym>URI</acronym></entry>
  24. <entry>Module_Controller::action</entry>
  25. </row>
  26. </thead>
  27. <tbody>
  28. <row>
  29. <entry><constant>GET</constant></entry>
  30. <entry><filename>/product/ratings/</filename></entry>
  31. <entry><methodname>Product_RatingsController::indexAction()</methodname></entry>
  32. </row>
  33. <row>
  34. <entry><constant>GET</constant></entry>
  35. <entry><filename>/product/ratings/:id</filename></entry>
  36. <entry><methodname>Product_RatingsController::getAction()</methodname></entry>
  37. </row>
  38. <row>
  39. <entry><constant>POST</constant></entry>
  40. <entry><filename>/product/ratings</filename></entry>
  41. <entry><methodname>Product_RatingsController::postAction()</methodname></entry>
  42. </row>
  43. <row>
  44. <entry><constant>PUT</constant></entry>
  45. <entry><filename>/product/ratings/:id</filename></entry>
  46. <entry><methodname>Product_RatingsController::putAction()</methodname></entry>
  47. </row>
  48. <row>
  49. <entry><constant>DELETE</constant></entry>
  50. <entry><filename>/product/ratings/:id</filename></entry>
  51. <entry>
  52. <methodname>Product_RatingsController::deleteAction()</methodname>
  53. </entry>
  54. </row>
  55. <row>
  56. <entry><constant>POST</constant></entry>
  57. <entry><filename>/product/ratings/:id?_method=PUT</filename></entry>
  58. <entry><methodname>Product_RatingsController::putAction()</methodname></entry>
  59. </row>
  60. <row>
  61. <entry><constant>POST</constant></entry>
  62. <entry><filename>/product/ratings/:id?_method=DELETE</filename></entry>
  63. <entry>
  64. <methodname>Product_RatingsController::deleteAction()</methodname>
  65. </entry>
  66. </row>
  67. </tbody>
  68. </tgroup>
  69. </table>
  70. <sect4 id="zend.rest.route_usage">
  71. <title>Zend_Rest_Route 利用法</title>
  72. <para>
  73. <classname>Zend_Rest_Route</classname>をアプリケーション全てで有効にするには、
  74. 構成パラメータ無しで構築して、フロントコントローラにデフォルトのルートとして追加してください。
  75. </para>
  76. <programlisting language="php"><![CDATA[
  77. $front = Zend_Controller_Front::getInstance();
  78. $restRoute = new Zend_Rest_Route($front);
  79. $front->getRouter()->addRoute('default', $restRoute);
  80. ]]></programlisting>
  81. <note>
  82. <para>
  83. もし<classname>Zend_Rest_Route</classname>が有効なモジュール、
  84. コントローラまたはアクションにマッチできなければ、<constant>FALSE</constant>を返します。
  85. そして、ルータはルータのなかの次のルートを使ってマッチを試みます。
  86. </para>
  87. </note>
  88. <para>
  89. 特定のモジュールで<classname>Zend_Rest_Route</classname>を有効にするには、
  90. コンストラクタの3番目の引数としてモジュール名の配列を使って構成します。
  91. </para>
  92. <programlisting language="php"><![CDATA[
  93. $front = Zend_Controller_Front::getInstance();
  94. $restRoute = new Zend_Rest_Route($front, array(), array('product'));
  95. $front->getRouter()->addRoute('rest', $restRoute);
  96. ]]></programlisting>
  97. <para>
  98. 特定のコントローラで<classname>Zend_Rest_Route</classname>を有効にするには、
  99. コントローラ名の配列を各モジュールの配列の要素の値として追加します。
  100. </para>
  101. <programlisting language="php"><![CDATA[
  102. $front = Zend_Controller_Front::getInstance();
  103. $restRoute = new Zend_Rest_Route($front, array(), array(
  104. 'product' => array('ratings')
  105. ));
  106. $front->getRouter()->addRoute('rest', $restRoute);
  107. ]]></programlisting>
  108. </sect4>
  109. <sect4 id="zend.rest.route_config">
  110. <title>Zend_Rest_Route with Zend_Config_Ini</title>
  111. <para>
  112. <acronym>INI</acronym> 構成ファイルから <classname>Zend_Rest_Route</classname> を使うには、
  113. ルート型のパラメータを使用して、構成オプションを設定します。
  114. </para>
  115. <programlisting language="ini"><![CDATA[
  116. routes.rest.type = Zend_Rest_Route
  117. routes.rest.defaults.controller = object
  118. routes.rest.mod = project,user
  119. ]]></programlisting>
  120. <!-- TODO : to be translated -->
  121. <para>
  122. The 'type' option designates the RESTful routing config type.
  123. The 'defaults' option is used to specify custom default
  124. module, controller, and/or actions for the route. All other options
  125. in the config group are treated as RESTful module names, and their
  126. values are RESTful controller names. The example config defines
  127. <classname>Mod_ProjectController</classname> and <classname>Mod_UserController</classname> as RESTful controllers.
  128. </para>
  129. <para>
  130. そして、Rewrite ルータ・オブジェクトの <methodname>addConfig()</methodname> メソッドを使います。
  131. </para>
  132. <programlisting language="php"><![CDATA[
  133. $config = new Zend_Config_Ini('path/to/routes.ini');
  134. $router = new Zend_Controller_Router_Rewrite();
  135. $router->addConfig($config, 'routes');
  136. ]]></programlisting>
  137. </sect4>
  138. <sect4 id="zend.rest.controller">
  139. <title>Zend_Rest_Controller</title>
  140. <para>
  141. <classname>Zend_Rest_Route</classname>を使う
  142. コントローラの開発を助けるか誘導するためには、
  143. <classname>Zend_Rest_Controller</classname>からコントローラを拡張してください。
  144. <classname>Zend_Rest_Controller</classname>では、
  145. RESTfulなリソースのために5つの最も一般的に必要とされる操作を
  146. 抽象的なアクション・メソッドの形で定義します。
  147. </para>
  148. <itemizedlist>
  149. <listitem>
  150. <para>
  151. <emphasis><methodname>indexAction()</methodname></emphasis> -
  152. リソースのインデックスを取得して、それをビューに割り当てます。
  153. </para>
  154. </listitem>
  155. <listitem>
  156. <para>
  157. <emphasis><methodname>getAction()</methodname></emphasis> -
  158. <acronym>URI</acronym>で識別される単一のリソースを取得して、それをビューに割り当てます。
  159. </para>
  160. </listitem>
  161. <listitem>
  162. <para>
  163. <emphasis><methodname>postAction()</methodname></emphasis> -
  164. 単一の新しいリソースを受け取って、その状態を持続します。
  165. </para>
  166. </listitem>
  167. <listitem>
  168. <para>
  169. <emphasis><methodname>putAction()</methodname></emphasis> -
  170. <acronym>URI</acronym>で識別される単一のリソースを受け取って、その状態を持続します。
  171. </para>
  172. </listitem>
  173. <listitem>
  174. <para>
  175. <emphasis><methodname>deleteAction()</methodname></emphasis> -
  176. <acronym>URI</acronym>で識別される単一のリソースを削除します。
  177. </para>
  178. </listitem>
  179. </itemizedlist>
  180. </sect4>
  181. </sect3>
  182. <!--
  183. vim:se ts=4 sw=4 et:
  184. -->