如何在 Zend 中传递变量? [英] How can i pass variables in Zend?
问题描述
我的索引中有一个表单,当它有效时,它会重定向到一个新视图,我希望在该新视图上获取表单中输入的名称,我该怎么做?
I have a form on my index, and when it valid, it redirects to a new view, and i want on that new view to get the name that was entered in the form, how can i do that?
我的控制器:
public function indexAction()
{
// action body
$eform = new Application_Form_Eform();
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($eform->isValid($formData)) {
$nameInput = $eform->getValue('nameInput');
$this->_helper->redirector->gotoRoute(array('controller'=> 'index','action' =>'result', 'email' => $nameInput));
$this->_helper->redirector('result');
exit;
} else {
$eform->populate($formData);
}
}
$this->view->form = $eform;
}
public function resultAction()
{
$nameInput = $this->_getParam('email');
$this->view->email = $nameInput;
}
结果.phtml
<?php echo $this->name;?>
如何传递在表单中输入的变量 name
并将其显示在 resultAction
的新视图上?谢谢!
how can i pass the variable name
that was entered in the form and display it on the new view of resultAction
? Thanks!
推荐答案
Zend_Controller_Action_Helper_Redirector::gotoRoute
之后不需要再执行 Zend_Controller_Action_Helper_Redirector::direct
方法,离开仅第一次调用,并使用 gotoRouteAndExit
代替:
You don't need to execute Zend_Controller_Action_Helper_Redirector::direct
method after Zend_Controller_Action_Helper_Redirector::gotoRoute
, leave only the first call, and use gotoRouteAndExit
instead:
$this->_helper->redirector->gotoRouteAndExit (array(
'controller' => 'index',
'action' =>'result',
'email' => $nameInput));
这篇关于如何在 Zend 中传递变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!