Zend: Passing variable through redirect

Sara Tibbetts

Right now I have the following method in my ChildFamily controller:

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>";
            }
        }

    }

I want to make $error available after the redirect. I tried passing it into the array (as shown above) but it seems that I can't access it. Is there a better way to do this? If at all possible, I don't want the value of the error to be in the path.

Greg Gomez

According to the docs:

The FlashMessenger helper allows you to pass messages that the user may need to see on the next request.

http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.flashmessenger

http://framework.zend.com/manual/current/en/modules/zend.view.helpers.flash-messenger.html

Will that work?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive