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

Moo*_*oon 9 zend-framework

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

$this->_helper->redirector("index");
Run Code Online (Sandbox Code Playgroud)

Zend Documenataion对此没有任何说明.

And*_*lam 19

当然.这是Action Helpers文档中的代码示例(请参阅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'));
    }
}
Run Code Online (Sandbox Code Playgroud)


Rah*_*man 8

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

$this->_helper->redirector('action', 'controller', 'module', array('param1' => 'value1'));
Run Code Online (Sandbox Code Playgroud)