2014-07-14 73 views
0

我有一個與時間有很多關係的模型課程。我如何更新所有的時間。在phalcon中保存一對多關係數據

  $course_Timeing = $course->courseTimings; 
      $m = new MultipleIterator(); 
      $m->attachIterator(new ArrayIterator($this->request->getPost('date', 'string')), 'date'); 
      $m->attachIterator(new ArrayIterator($this->request->getPost('timeFrom', 'string')), 'timeFrom'); 
      $m->attachIterator(new ArrayIterator($this->request->getPost('timeTo', 'string')), 'timeTo'); 
      $i = 0; 
      foreach ($m as $unit) { 
       //print_r($unit); 
       if (!empty($unit[0]) && !empty($unit[1]) && !empty($unit[2])) { 
        $course_Timeing = $course->courseTimings[$i]; 
        $course_Timeing->assign(array(
         //'course_id' => $course->id, 
         'date' => date('Y-m-d', strtotime($unit[0])), 
         'timeFrom' => date('H:i:s', strtotime($unit[1])), 
         'timeTo' => date('H:i:s', strtotime($unit[2])), 
        )); 
       } 
       $i++; 
      } 

$課程 - >保存不保存計時

回答

0

嗯,我找到了出路由

   $course_Timeing = $course->courseTimings; 
       $m = new MultipleIterator(); 
       $m->attachIterator(new ArrayIterator($this->request->getPost('date', 'string')), 'date'); 
       $m->attachIterator(new ArrayIterator($this->request->getPost('timeFrom', 'string')), 'timeFrom'); 
       $m->attachIterator(new ArrayIterator($this->request->getPost('timeTo', 'string')), 'timeTo'); 
       $i = 0; 
       foreach ($m as $unit) { 
        //print_r($unit); 
        if (!empty($unit[0]) && !empty($unit[1]) && !empty($unit[2])) { 
         //$course_Timeing = $course->courseTimings[$i]; 
         $course_Timeing[$i]->assign(array(
          //'course_id' => $course->id, 
          'date' => date('Y-m-d', strtotime($unit[0])), 
          'timeFrom' => date('H:i:s', strtotime($unit[1])), 
          'timeTo' => date('H:i:s', strtotime($unit[2])), 
         )); 
         if (!$course_Timeing[$i]->save()) { 
          foreach ($course_Timeing[$i]->getMessages() as $message) { 
           $this->flash->error($message); 
          } 
         } 
        } 
        $i++; 
       }