Zend_Controller-Router-Route-Rest.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 20078 -->
  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. <!-- TODO : to be translated -->
  110. <sect4 id="zend.rest.route_config">
  111. <title>Zend_Rest_Route with Zend_Config_Ini</title>
  112. <para>
  113. To use Zend_Rest_Route from an INI config file, use a route type
  114. parameter and set the config options:
  115. </para>
  116. <programlisting language="ini"><![CDATA[
  117. routes.rest.type = Zend_Rest_Route
  118. routes.rest.defaults.controller = object
  119. routes.rest.mod = project,user
  120. ]]></programlisting>
  121. <para>The 'type' option designates the RESTful routing config type.
  122. The 'defaults' option is used to specify custom default
  123. module, controller, and/or actions for the route. All other options
  124. in the config group are treated as RESTful module names, and their
  125. values are RESTful controller names. The example config defines
  126. Mod_ProjectController and Mod_UserController as RESTful controllers.</para>
  127. <para>Then use the addConfig() method of the Rewrite router object:</para>
  128. <programlisting language="php"><![CDATA[
  129. $config = new Zend_Config_Ini('path/to/routes.ini');
  130. $router = new Zend_Controller_Router_Rewrite();
  131. $router->addConfig($config, 'routes');
  132. ]]></programlisting>
  133. </sect4>
  134. <sect4 id="zend.rest.controller">
  135. <title>Zend_Rest_Controller</title>
  136. <para>
  137. <classname>Zend_Rest_Route</classname>を使う
  138. コントローラの開発を助けるか誘導するためには、
  139. <classname>Zend_Rest_Controller</classname>からコントローラを拡張してください。
  140. <classname>Zend_Rest_Controller</classname>では、
  141. RESTfulなリソースのために5つの最も一般的に必要とされる操作を
  142. 抽象的なアクション・メソッドの形で定義します。
  143. </para>
  144. <itemizedlist>
  145. <listitem>
  146. <para>
  147. <emphasis><methodname>indexAction()</methodname></emphasis> -
  148. リソースのインデックスを取得して、それをビューに割り当てます。
  149. </para>
  150. </listitem>
  151. <listitem>
  152. <para>
  153. <emphasis><methodname>getAction()</methodname></emphasis> -
  154. <acronym>URI</acronym>で識別される単一のリソースを取得して、それをビューに割り当てます。
  155. </para>
  156. </listitem>
  157. <listitem>
  158. <para>
  159. <emphasis><methodname>postAction()</methodname></emphasis> -
  160. 単一の新しいリソースを受け取って、その状態を持続します。
  161. </para>
  162. </listitem>
  163. <listitem>
  164. <para>
  165. <emphasis><methodname>putAction()</methodname></emphasis> -
  166. <acronym>URI</acronym>で識別される単一のリソースを受け取って、その状態を持続します。
  167. </para>
  168. </listitem>
  169. <listitem>
  170. <para>
  171. <emphasis><methodname>deleteAction()</methodname></emphasis> -
  172. <acronym>URI</acronym>で識別される単一のリソースを削除します。
  173. </para>
  174. </listitem>
  175. </itemizedlist>
  176. </sect4>
  177. </sect3>
  178. <!--
  179. vim:se ts=4 sw=4 et:
  180. -->