Zend_Controller-ActionHelpers-FlashMessenger.xml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.basicusage">
  21. <title>Basic Usage Example</title>
  22. <para>
  23. The usage example below shows the use of the flash messenger at its
  24. most basic. When the action <filename>/some/my</filename> is called, it adds
  25. the flash message "Record Saved!" A subsequent request to the action
  26. <filename>/some/my-next-request</filename> will retrieve it (and thus delete
  27. it as well).
  28. </para>
  29. <programlisting language="php"><![CDATA[
  30. class SomeController extends Zend_Controller_Action
  31. {
  32. /**
  33. * FlashMessenger
  34. *
  35. * @var Zend_Controller_Action_Helper_FlashMessenger
  36. */
  37. protected $_flashMessenger = null;
  38. public function init()
  39. {
  40. $this->_flashMessenger =
  41. $this->_helper->getHelper('FlashMessenger');
  42. $this->initView();
  43. }
  44. public function myAction()
  45. {
  46. /**
  47. * default method of getting
  48. * Zend_Controller_Action_Helper_FlashMessenger instance
  49. * on-demand
  50. */
  51. $this->_flashMessenger->addMessage('Record Saved!');
  52. }
  53. public function myNextRequestAction()
  54. {
  55. $this->view->messages = $this->_flashMessenger->getMessages();
  56. $this->render();
  57. }
  58. }
  59. ]]></programlisting>
  60. </sect4>
  61. </sect3>