Zend:通过重定向传递变量
Zend: Passing variable through redirect
现在我的 ChildFamily
控制器中有以下方法:
public function statusAction(){
$form = new AddChildForm("add");
$view = array( 'form'=>$form );
$familyId = $this->params()->fromRoute("id");
$error = $this->params();
// If POST, add child to family
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost()->toArray());
if ($form->isValid()) {
try {
$data = $form->getData();
// Clean data
$childId = intval(trim($data[AddChildForm::KEY_CHILD_ID]));
// Add child to the currently displayed family
$cf = new ChildFamily();
$error = $cf->addChildToFamily($familyId, $childId);
if ($error) {
}
// Reload page to update childlist
return $this->redirect()->toRoute('family', array('action' => 'status', 'id' => $familyId, 'error' => $error ));
} catch (\Exception $e) {
$p = $e->getPrevious();
if (is_null($p)) {
$p = $e;
}
$view['error'] = "Error code [ " . $p->getCode() . " ] : " . $p->getMessage() . "<br/><pre>"
. $e->getTraceAsString() . "</pre>";
}
}
}
我想在重定向后使 $error
可用。我尝试将它传递到数组中(如上所示),但似乎无法访问它。有一个更好的方法吗?如果可能的话,我不希望错误的值出现在路径中。
根据文档:
FlashMessenger 助手允许您传递用户可能需要在下一个请求中看到的消息。
http://framework.zend.com/manual/current/en/modules/zend.view.helpers.flash-messenger.html
这行得通吗?
现在我的 ChildFamily
控制器中有以下方法:
public function statusAction(){
$form = new AddChildForm("add");
$view = array( 'form'=>$form );
$familyId = $this->params()->fromRoute("id");
$error = $this->params();
// If POST, add child to family
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost()->toArray());
if ($form->isValid()) {
try {
$data = $form->getData();
// Clean data
$childId = intval(trim($data[AddChildForm::KEY_CHILD_ID]));
// Add child to the currently displayed family
$cf = new ChildFamily();
$error = $cf->addChildToFamily($familyId, $childId);
if ($error) {
}
// Reload page to update childlist
return $this->redirect()->toRoute('family', array('action' => 'status', 'id' => $familyId, 'error' => $error ));
} catch (\Exception $e) {
$p = $e->getPrevious();
if (is_null($p)) {
$p = $e;
}
$view['error'] = "Error code [ " . $p->getCode() . " ] : " . $p->getMessage() . "<br/><pre>"
. $e->getTraceAsString() . "</pre>";
}
}
}
我想在重定向后使 $error
可用。我尝试将它传递到数组中(如上所示),但似乎无法访问它。有一个更好的方法吗?如果可能的话,我不希望错误的值出现在路径中。
根据文档:
FlashMessenger 助手允许您传递用户可能需要在下一个请求中看到的消息。
http://framework.zend.com/manual/current/en/modules/zend.view.helpers.flash-messenger.html
这行得通吗?