File: Zend_Controller-ActionHelpers-FlashMessenger.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (191 lines) | stat: -rw-r--r-- 8,749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect3 id="zend.controller.actionhelpers.flashmessenger">
    <title>FlashMessenger</title>

    <sect4 id="zend.controller.actionhelper.flashmessenger.introduction">
        <title>Introduction</title>

        <para>
            The <emphasis>FlashMessenger</emphasis> helper allows you to pass messages
            that the user may need to see on the next request. To accomplish
            this, <emphasis>FlashMessenger</emphasis> uses
            <classname>Zend_Session_Namespace</classname> to store messages for future or
            next request retrieval. It is generally a good idea that if you
            plan on using <classname>Zend_Session</classname> or
            <classname>Zend_Session_Namespace</classname>, that you initialize with
            <methodname>Zend_Session::start()</methodname> in your bootstrap file. (See the
            <link linkend="zend.session.advanced_usage.starting_a_session">Zend_Session</link>
            documentation for more details on its usage.)
        </para>
    </sect4>

    <sect4 id="zend.controller.actionhelper.flashmessenger.api">
        <title>Available Methods</title>

        <para>
            General methods:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <methodname>setNamespace($namespace='default')</methodname> is used to set the namespace
                     into which messages are stored by default. 
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>getNamespace()</methodname> is used to retrieve the name of the 
                    default namespace.  The default namespace is 'default'.
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>resetNamespace()</methodname> is used to reset the namespace name
                    to the default value, 'default'.
                </para>
            </listitem>
        </itemizedlist>

        <para>
            Methods for manipulating messages set in the previous request:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <methodname>hasMessages($namespace=NULL)</methodname> is used to determine
                    if messages have been carried from a previous request by the flash messenger.  The
                    optional argument <varname>$namespace</varname> specifies which namespace to look in.
                    If the <varname>$namespace</varname> argument is omitted, the value returned by
                    <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>getMessages($namespace=NULL)</methodname> is used to retrieve the
                    messages which have been carried from a previous request by the flash messenger.  The
                    optional argument <varname>$namespace</varname> specifies which namespace to pull from.
                    If the <varname>$namespace</varname> argument is omitted, the value returned by
                    <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>getIterator($namespace=NULL)</methodname> wraps the return value of 
                    <methodname>getMessages()</methodname> in an instance of <classname>ArrayObject</classname>.
                    If the <varname>$namespace</varname> argument is omitted, the value returned by
                    <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>count($namespace=NULL)</methodname> returns the number of messages contained
                    in the specified namespace.  If the <varname>$namespace</varname> argument is omitted, the 
                    value returned by <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>clearMessages($namespace=NULL)</methodname> is used to clear all the
                    messages which have been carried from a previous request by the flash messenger.  The
                    optional argument <varname>$namespace</varname> specifies which namespace to clear out.
                    If the <varname>$namespace</varname> argument is omitted, the value returned by
                    <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
        </itemizedlist>

        <para>
            Methods for manipulating messages set in the current request:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <methodname>addMessage($message, $namespace=NULL)</methodname> is used to add a new 
                    message to the current request.  <varname>$message</varname> contains the message
                    to be added, and the optional argument <varname>$namespace</varname> will specify
                    the namespace.  If the <varname>$namespace</varname> argument is omitted, the value
                    returned by <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>hasCurrentMessages($namespace=NULL)</methodname> is used to determine
                    if messages have been added to the flash messenger during the current request.  The
                    optional argument <varname>$namespace</varname> specifies which namespace to look in.
                    If the <varname>$namespace</varname> argument is omitted, the value returned by
                    <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>getCurrentMessages($namespace=NULL)</methodname> is used to retrieve the
                    messages which have been added to the flash messenger during the current request.  The
                    optional argument <varname>$namespace</varname> specifies which namespace to pull from.
                    If the <varname>$namespace</varname> argument is omitted, the value returned by
                    <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
            <listitem>
                <para>
                    <methodname>clearCurrentMessages($namespace=NULL)</methodname> is used to clear all the
                    messages which have been added to the flash messenger during the current request.  The
                    optional argument <varname>$namespace</varname> specifies which namespace to clear out.
                    If the <varname>$namespace</varname> argument is omitted, the value returned by
                    <methodname>getNamespace()</methodname> will be used.
                </para>
            </listitem>
        </itemizedlist>

    </sect4>

    <sect4 id="zend.controller.actionhelper.flashmessenger.basicusage">
        <title>Basic Usage Example</title>

        <para>
            The usage example below shows the use of the flash messenger at its
            most basic. When the action <filename>/some/my</filename> is called, it adds
            the flash message "Record Saved!" A subsequent request to the action
            <filename>/some/my-next-request</filename> will retrieve it (and thus delete
            it as well).
        </para>

        <programlisting language="php"><![CDATA[
class SomeController extends Zend_Controller_Action
{
    /**
     * FlashMessenger
     *
     * @var Zend_Controller_Action_Helper_FlashMessenger
     */
    protected $_flashMessenger = null;

    public function init()
    {
        $this->_flashMessenger =
            $this->_helper->getHelper('FlashMessenger');
        $this->initView();
    }

    public function myAction()
    {
        /**
         * default method of getting
         * Zend_Controller_Action_Helper_FlashMessenger instance
         * on-demand
         */
        $this->_flashMessenger->addMessage('Record Saved!');
    }

    public function myNextRequestAction()
    {
        $this->view->messages = $this->_flashMessenger->getMessages();
        $this->render();
    }
}
]]></programlisting>
    </sect4>
</sect3>