Zend:使用参数重定向到动作 [英] Zend: Redirect to Action with parameters
问题描述
我正在使用zend框架.我正在使用以下语句重定向到其他操作.
I am using zend framework. I am using the following statement to redirect to another action.
$this->_helper->redirector('some_action');
以上语句运行正常,并调用了"some_action".现在,我想像这样将一些参数传递给"some_action".
Above statement is working perfectly and 'some_action' is called. Now I want to pass some parameters to 'some_action' like this.
some_action?uname=username&umail=username@example.com
以及如何在被调用的动作中获取参数.通常我们会这样:
And how to get parameters in called action. Usually we do like this:
$userName = $_REQUEST['uname'];
$usermail = $_REQUEST['umail'];
如何执行此操作?请提供示例代码.谢谢
How to perform this? Example code please. Thanks
推荐答案
使用Zend_Controller_Action::redirect()
方法(该方法仅传递给Sarfraz的辅助方法)
Use the Zend_Controller_Action::redirect()
method (which just passes through to Sarfraz's helper method)
$this->redirect('/module/controller/action/username/robin/email/robin@example.com');
注意:从Zend Framework 1.7开始不推荐使用_redirect()
方法.改为使用redirect()
.
Note: _redirect()
method is deprecated as of Zend Framework 1.7. Use redirect()
instead.
然后在被调用的操作中:
And then in the called action:
$username = $this->_getParam('username');
$email = $this->_getParam('email');
_getParam()使用第二个可选参数,如果找不到该参数,则默认将其设置为变量.
_getParam() takes a second optional argument which is set to the variable as a default if the parameter isn't found.
这篇关于Zend:使用参数重定向到动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!