Zend_Controller-ActionHelpers-FlashMessenger.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.controller.actionhelpers.flashmessenger">
  4. <title>FlashMessenger</title>
  5. <sect4 id="zend.controller.actionhelper.flashmessenger.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. The <emphasis>FlashMessenger</emphasis> helper allows you to pass messages
  9. that the user may need to see on the next request. To accomplish
  10. this, <emphasis>FlashMessenger</emphasis> uses
  11. <classname>Zend_Session_Namespace</classname> to store messages for future or
  12. next request retrieval. It is generally a good idea that if you
  13. plan on using <classname>Zend_Session</classname> or
  14. <classname>Zend_Session_Namespace</classname>, that you initialize with
  15. <methodname>Zend_Session::start()</methodname> in your bootstrap file. (See the
  16. <link linkend="zend.session.advanced_usage.starting_a_session">Zend_Session</link>
  17. documentation for more details on its usage.)
  18. </para>
  19. </sect4>
  20. <sect4 id="zend.controller.actionhelper.flashmessenger.api">
  21. <title>Available Methods</title>
  22. <para>
  23. General methods:
  24. </para>
  25. <itemizedlist>
  26. <listitem>
  27. <para>
  28. <methodname>setNamespace($namespace='default')</methodname> is used to set the namespace
  29. into which messages are stored by default.
  30. </para>
  31. </listitem>
  32. <listitem>
  33. <para>
  34. <methodname>getNamespace()</methodname> is used to retrieve the name of the
  35. default namespace. The default namespace is 'default'.
  36. </para>
  37. </listitem>
  38. <listitem>
  39. <para>
  40. <methodname>resetNamespace()</methodname> is used to reset the namespace name
  41. to the default value, 'default'.
  42. </para>
  43. </listitem>
  44. </itemizedlist>
  45. <para>
  46. Methods for manipulating messages set in the previous request:
  47. </para>
  48. <itemizedlist>
  49. <listitem>
  50. <para>
  51. <methodname>hasMessages($namespace=NULL)</methodname> is used to determine
  52. if messages have been carried from a previous request by the flash messenger. The
  53. optional argument <varname>$namespace</varname> specifies which namespace to look in.
  54. If the <varname>$namespace</varname> argument is omitted, the value returned by
  55. <methodname>getNamespace()</methodname> will be used.
  56. </para>
  57. </listitem>
  58. <listitem>
  59. <para>
  60. <methodname>getMessages($namespace=NULL)</methodname> is used to retrieve the
  61. messages which have been carried from a previous request by the flash messenger. The
  62. optional argument <varname>$namespace</varname> specifies which namespace to pull from.
  63. If the <varname>$namespace</varname> argument is omitted, the value returned by
  64. <methodname>getNamespace()</methodname> will be used.
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. <methodname>getIterator($namespace=NULL)</methodname> wraps the return value of
  70. <methodname>getMessages()</methodname> in an instance of <classname>ArrayObject</classname>.
  71. If the <varname>$namespace</varname> argument is omitted, the value returned by
  72. <methodname>getNamespace()</methodname> will be used.
  73. </para>
  74. </listitem>
  75. <listitem>
  76. <para>
  77. <methodname>count($namespace=NULL)</methodname> returns the number of messages contained
  78. in the specified namespace. If the <varname>$namespace</varname> argument is omitted, the
  79. value returned by <methodname>getNamespace()</methodname> will be used.
  80. </para>
  81. </listitem>
  82. <listitem>
  83. <para>
  84. <methodname>clearMessages($namespace=NULL)</methodname> is used to clear all the
  85. messages which have been carried from a previous request by the flash messenger. The
  86. optional argument <varname>$namespace</varname> specifies which namespace to clear out.
  87. If the <varname>$namespace</varname> argument is omitted, the value returned by
  88. <methodname>getNamespace()</methodname> will be used.
  89. </para>
  90. </listitem>
  91. </itemizedlist>
  92. <para>
  93. Methods for manipulating messages set in the current request:
  94. </para>
  95. <itemizedlist>
  96. <listitem>
  97. <para>
  98. <methodname>addMessage($message, $namespace=NULL)</methodname> is used to add a new
  99. message to the current request. <varname>$message</varname> contains the message
  100. to be added, and the optional argument <varname>$namespace</varname> will specify
  101. the namespace. If the <varname>$namespace</varname> argument is omitted, the value
  102. returned by <methodname>getNamespace()</methodname> will be used.
  103. </para>
  104. </listitem>
  105. <listitem>
  106. <para>
  107. <methodname>hasCurrentMessages($namespace=NULL)</methodname> is used to determine
  108. if messages have been added to the flash messenger during the current request. The
  109. optional argument <varname>$namespace</varname> specifies which namespace to look in.
  110. If the <varname>$namespace</varname> argument is omitted, the value returned by
  111. <methodname>getNamespace()</methodname> will be used.
  112. </para>
  113. </listitem>
  114. <listitem>
  115. <para>
  116. <methodname>getCurrentMessages($namespace=NULL)</methodname> is used to retrieve the
  117. messages which have been added to the flash messenger during the current request. The
  118. optional argument <varname>$namespace</varname> specifies which namespace to pull from.
  119. If the <varname>$namespace</varname> argument is omitted, the value returned by
  120. <methodname>getNamespace()</methodname> will be used.
  121. </para>
  122. </listitem>
  123. <listitem>
  124. <para>
  125. <methodname>clearCurrentMessages($namespace=NULL)</methodname> is used to clear all the
  126. messages which have been added to the flash messenger during the current request. The
  127. optional argument <varname>$namespace</varname> specifies which namespace to clear out.
  128. If the <varname>$namespace</varname> argument is omitted, the value returned by
  129. <methodname>getNamespace()</methodname> will be used.
  130. </para>
  131. </listitem>
  132. </itemizedlist>
  133. </sect4>
  134. <sect4 id="zend.controller.actionhelper.flashmessenger.basicusage">
  135. <title>Basic Usage Example</title>
  136. <para>
  137. The usage example below shows the use of the flash messenger at its
  138. most basic. When the action <filename>/some/my</filename> is called, it adds
  139. the flash message "Record Saved!" A subsequent request to the action
  140. <filename>/some/my-next-request</filename> will retrieve it (and thus delete
  141. it as well).
  142. </para>
  143. <programlisting language="php"><![CDATA[
  144. class SomeController extends Zend_Controller_Action
  145. {
  146. /**
  147. * FlashMessenger
  148. *
  149. * @var Zend_Controller_Action_Helper_FlashMessenger
  150. */
  151. protected $_flashMessenger = null;
  152. public function init()
  153. {
  154. $this->_flashMessenger =
  155. $this->_helper->getHelper('FlashMessenger');
  156. $this->initView();
  157. }
  158. public function myAction()
  159. {
  160. /**
  161. * default method of getting
  162. * Zend_Controller_Action_Helper_FlashMessenger instance
  163. * on-demand
  164. */
  165. $this->_flashMessenger->addMessage('Record Saved!');
  166. }
  167. public function myNextRequestAction()
  168. {
  169. $this->view->messages = $this->_flashMessenger->getMessages();
  170. $this->render();
  171. }
  172. }
  173. ]]></programlisting>
  174. </sect4>
  175. </sect3>