How do I pass parameters using redirector helper in Zend Framework?
Is it possible to pass parameters ($_POST or $_GET) with redirectory helper in Zend Framework? The following code redirect to index action of current controller, but I would like to pass some parameters to it as well.
$this->_h开发者_如何学Goelper->redirector("index");
Zend Documenataion does not say anything about it.
Of course. This is a code sample from the Action Helpers documentation (see the Redirector
section, about 2/3 of the way down the page.) You may need to grab a reference to the redirector helper and call one of the goto*
methods like this code is doing.
class ForwardController extends Zend_Controller_Action
{
/**
* Redirector - defined for code completion
*
* @var Zend_Controller_Action_Helper_Redirector
*/
protected $_redirector = null;
public function init()
{
$this->_redirector = $this->_helper->getHelper('Redirector');
}
public function myAction()
{
/* do some stuff */
// Redirect to 'my-action' of 'my-controller' in the current
// module, using the params param1 => test and param2 => test2
$this->_redirector->gotoSimple('my-action',
'my-controller',
null,
array('param1' => 'test', 'param2' => 'test2'));
}
}
Pass an array as 4th parameter:
$this->_helper->redirector('action', 'controller', 'module', array('param1' => 'value1'));
精彩评论