Zend:通过重定向传递变量

时间:2016-02-16 15:09:26

标签: php variables redirect zend-framework

现在我的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可用。我尝试将其传递到数组中(如上所示),但似乎我无法访问它。有一个更好的方法吗?如果可能的话,我不希望错误的值在路径中。

1 个答案:

答案 0 :(得分:1)