I am using zend framework. I am using the following statement to redirect to another action.
$this->_helper->redirector('some_action');
Above statement is working perfectly and 'some_action' is called. Now I want to pass some parameters to 'some_action' like this.
some_action?uname=username&umail=username@example.com
And how to get parameters in called action. Usually we do like this:
$userName = $_REQUEST['uname'];
$usermail = $_REQUEST['umail'];
How to perform this? Example code please. Thanks
How you get the param sorta depends on where you are,
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.
Since you asked about login I will show you how I usually do it. Not that its the best way.
My LoginController's index view holds the form:
In the success action we do this:
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:
Then catch them both if they are set in the view:
You can also add $params say like for userid
I forgot to mention, of course this is assuming you have the routing setup to accept a $param. As an example the routing would look something like this for the page that is being redirected to in the example above:
/application/configs/application.ini
you can try with redirector:
You may want to try this:
Use the
Zend_Controller_Action::redirect()
method (which just passes through to Sarfraz's helper method)Note:
_redirect()
method is deprecated as of Zend Framework 1.7. Useredirect()
instead.And then in the called action:
_getParam() takes a second optional argument which is set to the variable as a default if the parameter isn't found.