Zend在会话中存储数据

时间:2014-05-12 14:11:27

标签: php session zend-framework

我是Zend和php的新手。对于一个项目,我需要一起收集3个ajax Zend Forms。我知道我需要使用会话来做到这一点,但我找不到任何有关如何做到这一点的信息。有人能帮我吗 ?

编辑:

    public function formResAction(){

        $form = new Front_Form_ResPhone();
        $bdd_Reservation = new Front_Model_DbTable_Reservation();

        if($this->getRequest()->isPost()){
            if($form->isValid($this->getRequest()->getPost())){
                // Données non valides

                $session = new Zend_Session_Namespace('forms');
                $formData = $form->getValues();
                $session->form1 = $formData;
                print_r ($session->form1);

                echo $this->view->bloc11Fid($formData);
                exit;
            }
            else{
                // Données non valides
//              echo "non valide";
            }
        }
        else{
            // Appel en GET
//              echo "GET";
        }
        echo $form;
        exit;

}

    public function formFidAction(){

            $form = new Front_Form_FidForm();
            $bdd_Reservation = new Front_Model_DbTable_Reservation();

        if($this->getRequest()->isPost()){
            if($form->isValid($this->getRequest()->getPost())){
                // Données non valides

                $session = new Zend_Session_Namespace('forms');
                $formData = $form->getValues();
                $session->form2 = $formData;
                print_r ($session->form2);

                echo $this->view->bloc11Fid2($formData);
                exit;
            }
            else{
                // Données non valides
//              echo "non valide";
            }
        }
        else{
            // Appel en GET
//              echo "GET";
        }
        echo $form;
        exit;

}

    public function formFid2Action(){

            $form = new Front_Form_FidForm2();
            $bdd_Reservation = new Front_Model_DbTable_Reservation();

        if($this->getRequest()->isPost()){
            if($form->isValid($this->getRequest()->getPost())){
                // Données non valides

                $session = new Zend_Session_Namespace('forms');
                $formData = $form->getValues();
                $session->form3 = $formData;
                print_r ($session->form3);  

                echo $this->view->bloc11Res($formData);

                exit;
            }
            else{
                // Données non valides
//              echo "non valide";
            }
        }
        else{
            // Appel en GET
//              echo "GET";
        }
        echo $form;
        exit;

}

public function resFormAction(){

        $form = new Front_Form_ResForm();
        $bdd_Reservation = new Front_Model_DbTable_Reservation();

        if($this->getRequest()->isPost()){
            if($form->isValid($this->getRequest()->getPost())){
                // Données non valides

                $session = new Zend_Session_Namespace('forms');
                $formData = $form->getValues();
                $session->form4 = $formData;
                print_r ($session);

                $bdd_Reservation->insert($forms);

                echo $this->view->bloc11Fel($formData);
                exit;


                exit;
            }
            else{
                // Données non valides
//              echo "non valide";
            }
        }
        else{
            // Appel en GET
//              echo "GET";
        }
        echo $form;
        exit;       
}

1 个答案:

答案 0 :(得分:2)

检查一下:

//create a session namespace
$session = new Zend_Session_Namespace('myapp');

$session->somevar = 'somevalue';

echo $session->somevar; //somevalue

Zend_Session_Namespace 有魔法吸气剂和设定器。

因此,如果未设置会话对象的属性,默认情况下它将为 NULL

http://framework.zend.com/manual/1.12/en/zend.session.basic_usage.html