如何在Zend Framework中使用重定向器助手传递参数?

时间:2010-03-31 10:42:43

标签: zend-framework

是否可以在Zend Framework中使用redirectory helper传递参数($ _POST或$ _GET)?以下代码重定向到当前控制器的索引操作,但我也希望将一些参数传递给它。

$this->_helper->redirector("index");

Zend Documenataion对此一无所知。

2 个答案:

答案 0 :(得分:19)

当然。这是来自Action Helpers documentation的代码示例(请参阅Redirector部分,大约是页面下方的2/3。)您可能需要获取对重定向器助手的引用并调用其中一个像这段代码的goto*方法正在做。

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'));
    }
}

答案 1 :(得分:8)

将数组作为第4个参数传递:

$this->_helper->redirector('action', 'controller', 'module', array('param1' => 'value1'));