如何在cakephp中插入数组数据

时间:2016-05-06 07:20:35

标签: php cakephp

我有3步表格, 在第一步中,我正在编写会话中的所有发布数据并重定向到addjob2。

在addjob2中,我在第二个会话变量中编写所有发布数据,如果一切正常,那么我就是执行函数addjob3,用于在数据库中插入所有数据。

现在问题是当我尝试插入所有数据时,

这将仅插入此$ data会话变量的数据。 并非所有$ values = Set :: merge($ name,$ data);

我需要在addjob3函数中插入$ value的所有数据。

public function addjob() {         
        if ($this->request->is('put') || $this->request->is('post'))
        {  
            $this->Session->write('name', $this->request->data);           
            $name = $this->Session->read('name');           
            if((!empty($name['Job']['customer_name'])) && (!empty($name['Job']['customer_no'])) && (!empty($name['Job']['customer_email'])))
            {
                 $this->redirect(array('controller' => 'jobs', 'action' => 'addjob2')); 
            }           

        }

    }

    public function addjob2()
    {      
         $name = $this->Session->read('name');       
         if(!empty($name)) 
          {  
             $this->Session->write('data', $this->request->data); 
             $data = $this->Session->read('data');             
             if((!empty($data['Job']['shipment_title'])) && (!empty($data['Job']['no_of_commodity'])) && (!empty($data['Job']['insurance_required'])))
              {
                $values= Set::merge($name, $data);              
                $this->addjob3();              
              }           

        }

    }


     public function addjob3($id = NULL) { 
        if ($this->request->is('put') || $this->request->is('post')) {          
            if (isset($id)) {
                $this->Job->id = $id;
            } else {
                $this->request->data['Job']['status'] = 1;  
                $this->request->data['Job']['job_type'] = 1; //this is used to update the job type private or public.
                $this->Job->create();
            }
            $this->Job->set($this->request->data);
            if ($this->Job->AddEdit()) { // ADDEdit is the validation name in model              
                if ($this->Job->save($this->request->data['Job'], false)) {
                    if (isset($id)) {
                    $this->Session->setFlash(__('Job has been updated sucessfully.'));

                    } else {
                    $this->Session->setFlash(__('Job has been added succesfully.'));

                    }
                    $this->redirect(array('controller' => 'jobs', 'action' => 'index'));
                }
            } else {
                $errors = $this->Job->validationErrors;

                $this->Session->setFlash(__('Please check your entry.'), 'flash_error');
            }
        }
        if (isset($id)) {
            $this->request->data = $this->Job->find('first', array('conditions' => array('id' => base64_decode($id))));
        }

    }

$ values的输出

Array
(
    [Job] => Array
        (
            [customer_name] => lucky
            [customer_no] => 9595434321
            [customer_email] => raj@gmail.com
            [transport_type] => 1
            [shipping_type] => 1
            [ship_category] => 1
            [cargo_type] => 2
            [country] => 10
            [state] => 1831
            [shipment_title] => Goods
            [no_of_commodity] => 2
            [insurance_required] => 1
            [pickup_address] => 452
            [pickup_location] => ngp
            [pickup_date] => Array
                (
                    [month] => 05
                    [day] => 06
                    [year] => 2016
                )

            [delivery_address] => nagpur
            [delivery_location] => wardhman
            [delivery_date] => Array
                (
                    [month] => 05
                    [day] => 06
                    [year] => 2016
                )

            [my_budget] => 2500
            [auction_end_date] => Array
                (
                    [month] => 05
                    [day] => 06
                    [year] => 2016
                )

        )

)

0 个答案:

没有答案