views:

230

answers:

1

Hi,

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.

+6  A: 

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'));
    }
}
Andy Shellam
@Andy Shellam // ah! How could I miss that! Thank you a lot!
Moon