Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>How you get the param sorta depends on where you are, </p> <p>You do not have to catch a request $param to achieve what you want to do here. You are just using the FlashMessenger helper to add a message to the stack. You then retrieve the message within the action where you want to show the message, then assign it to the view as I do in the successAction. Keep in mind that you can pass any $var or array of data by assigning it in the controller like: $this->view->var = $var; Within the view that will then be accessed as $this->var.</p> <p>Since you asked about login I will show you how I usually do it. Not that its the best way.</p> <p>My LoginController's index view holds the form:</p> <pre><code> public function indexAction() { $form = new Zfcms_Form_Login; $this-&gt;view-&gt;form = $form; /*check for valid input authenticate using adapter persist user record to session redirect to original request URL if present*/ if ($this-&gt;getRequest()-&gt;isPost()) { if ($form-&gt;isValid($this-&gt;getRequest()-&gt;getPost())) { $values = $form-&gt;getValues(); $authAdapter = $this-&gt;getAuthAdapter(); # get the username and password from the form $username = $values['username']; $password = $values['password']; # pass to the adapter the submitted username and password $authAdapter-&gt;setIdentity($username) -&gt;setCredential($password); $auth = Zend_Auth::getInstance(); $result = $auth-&gt;authenticate($authAdapter); if ($result-&gt;isValid()) { # all info about this user from the login table # ommit only the password, we don't need that $userInfo = $authAdapter-&gt;getResultRowObject(null, 'password'); # the default storage is a session with namespace Zend_Auth $authStorage = $auth-&gt;getStorage(); $authStorage-&gt;write($userInfo); $session = new Zend_Session_Namespace('zfcms.auth'); if (isset($session-&gt;requestURL)) { $url = $session-&gt;requestURL; unset($session-&gt;requestURL); $this-&gt;_redirect($url); } else { $this-&gt;_helper-&gt;getHelper('FlashMessenger') -&gt;addMessage('You were successfully logged in as&amp;nbsp;' . $userInfo-&gt;username); $this-&gt;_redirect('/login/success'); } } else { $this-&gt;view-&gt;message = 'You could not be logged in. Please try again.'; } } } } </code></pre> <p>In the success action we do this:</p> <pre><code>public function successAction() { if ($this-&gt;_helper-&gt;getHelper('FlashMessenger')-&gt;getMessages()) { $this-&gt;view-&gt;messages = $this-&gt;_helper -&gt;getHelper('FlashMessenger') -&gt;getMessages(); } else { $this-&gt;_redirect('/login/success'); } } </code></pre> <p>In the view script we can do something like what I have below. The reason I do it this way is that sometimes I will pass only a single message in a controller, in this case I simply use: </p> <pre><code>$this-&gt;view-&gt;message = 'message goes here'; </code></pre> <p>Then catch them both if they are set in the view:</p> <pre><code>&lt;?php if(isset($this-&gt;message) || isset($this-&gt;messages)): ?&gt; &lt;?php if(is_array($this-&gt;messages)) { echo implode($this-&gt;messages); } else { echo $this-&gt;message; }?&gt; &lt;?php endif ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload