2
0

Zend_Controller-Router-Route-Rest.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 16595 -->
  3. <!-- Reviewed: no -->
  4. <sect3 id="zend.controller.router.routes.rest">
  5. <title>Zend_Rest_Route</title>
  6. <para>
  7. The <classname>Zend_Rest</classname> component contains a RESTful route
  8. for <classname>Zend_Controller_Router_Rewrite</classname>. This route
  9. offers a standardized routing scheme that routes requests by translating
  10. the <acronym>HTTP</acronym> method and the <acronym>URI</acronym>
  11. to a module, controller, and action. The table below provides an overview
  12. of how request methods and <acronym>URI</acronym>'s are routed.
  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>Method</entry>
  23. <entry><acronym>URI</acronym></entry>
  24. <entry>Module_Controller::action</entry>
  25. </row>
  26. </thead>
  27. <tbody>
  28. <row>
  29. <entry>GET</entry>
  30. <entry><filename>/product/ratings/</filename></entry>
  31. <entry><methodname>Product_RatingsController::indexAction()</methodname></entry>
  32. </row>
  33. <row>
  34. <entry>GET</entry>
  35. <entry><filename>/product/ratings/:id</filename></entry>
  36. <entry><methodname>Product_RatingsController::getAction()</methodname></entry>
  37. </row>
  38. <row>
  39. <entry>POST</entry>
  40. <entry><filename>/product/ratings</filename></entry>
  41. <entry><methodname>Product_RatingsController::postAction()</methodname></entry>
  42. </row>
  43. <row>
  44. <entry>PUT</entry>
  45. <entry><filename>/product/ratings/:id</filename></entry>
  46. <entry><methodname>Product_RatingsController::putAction()</methodname></entry>
  47. </row>
  48. <row>
  49. <entry>DELETE</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>POST</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>POST</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. <para>
  71. To enable <classname>Zend_Rest_Route</classname> for an entire
  72. application, construct it with no config params and add it as the
  73. default route on the front controller:
  74. </para>
  75. <programlisting language="php"><![CDATA[
  76. $front = Zend_Controller_Front::getInstance();
  77. $restRoute = new Zend_Rest_Route($front);
  78. $front->getRouter()->addRoute('default', $restRoute);
  79. ]]></programlisting>
  80. <note>
  81. <para>
  82. If <classname>Zend_Rest_Route</classname> cannot match a valid
  83. module, controller, or action, it will return false and the router
  84. will attempt to match using the next route in the router.
  85. </para>
  86. </note>
  87. <para>
  88. To enable <classname>Zend_Rest_Route</classname> for specific modules,
  89. construct it with an array of module names as the 3rd constructor
  90. argument:
  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. To enable <classname>Zend_Rest_Route</classname> for specific
  99. controllers, add an array of controller names as the value of each
  100. module array element.
  101. </para>
  102. <programlisting language="php"><![CDATA[
  103. $front = Zend_Controller_Front::getInstance();
  104. $restRoute = new Zend_Rest_Route($front, array(), array(
  105. 'product' => array('ratings')
  106. ));
  107. $front->getRouter()->addRoute('rest', $restRoute);
  108. ]]></programlisting>
  109. <sect4 id="zend.rest.controller">
  110. <title>Zend_Rest_Controller</title>
  111. <para>
  112. To help guide development of Controllers for use with
  113. <classname>Zend_Rest_Route</classname>, extend your Controllers from
  114. <classname>Zend_Rest_Controller</classname>.
  115. <classname>Zend_Rest_Controller</classname> defines the 5 most-commonly
  116. needed operations for RESTful resources in the form of abstract action
  117. methods.
  118. </para>
  119. <itemizedlist>
  120. <listitem>
  121. <para>
  122. <emphasis><methodname>indexAction()</methodname></emphasis> -
  123. Should retrieve an index of resources and assign it to view.
  124. </para>
  125. </listitem>
  126. <listitem>
  127. <para>
  128. <emphasis><methodname>getAction()</methodname></emphasis> -
  129. Should retrieve a single resource identified by <acronym>URI</acronym>
  130. and assign it to view.
  131. </para>
  132. </listitem>
  133. <listitem>
  134. <para>
  135. <emphasis><methodname>postAction()</methodname></emphasis> -
  136. Should accept a new single resource and persist its state.
  137. </para>
  138. </listitem>
  139. <listitem>
  140. <para>
  141. <emphasis><methodname>putAction()</methodname></emphasis> -
  142. Should accept a single resource idenitifed by <acronym>URI</acronym>
  143. and persist its state.
  144. </para>
  145. </listitem>
  146. <listitem>
  147. <para>
  148. <emphasis><methodname>deleteAction()</methodname></emphasis> -
  149. Should delete a single resource identified by <acronym>URI</acronym>.
  150. </para>
  151. </listitem>
  152. </itemizedlist>
  153. </sect4>
  154. </sect3>
  155. <!--
  156. vim:se ts=4 sw=4 et:
  157. -->