Zend: Redirect to Action with parameters


Question

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

1
32
5/25/2012 5:25:04 AM

Accepted Answer

Use the Zend_Controller_Action::redirect() method (which just passes through to Sarfraz's helper method)

$this->redirect('/module/controller/action/username/robin/email/robin@example.com');

Note: _redirect() method is deprecated as of Zend Framework 1.7. Use redirect() instead.

And then in the called action:

$username = $this->_getParam('username');
$email = $this->_getParam('email');

_getParam() takes a second optional argument which is set to the variable as a default if the parameter isn't found.

29
5/28/2013 6:46:25 AM

you can try with redirector:

$params = array('user' => $user, 'mail' => $mail);
$this->_helper->redirector($action, $controller, $module, $params);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon