2016-02-16 88 views
1

传递变量现在,我有我的ChildFamily控制器下面的方法:Zend公司:通过重定向

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

回答