Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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->_helper->redirector("index");

Zend Documenataion does not say anything about it.

like image 693
Moon Avatar asked Mar 31 '10 10:03

Moon


2 Answers

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'));
    }
}
like image 115
Andy Shellam Avatar answered Oct 14 '22 03:10

Andy Shellam


Pass an array as 4th parameter:

$this->_helper->redirector('action', 'controller', 'module', array('param1' => 'value1'));
like image 8
R‌‌‌.. Avatar answered Oct 14 '22 04:10

R‌‌‌..