php - CakePHP Multiple Entry Fields w/ saveAll() HABTM multiple records Insert not saving -


i've found helpful tutorials , posts on stackoverflow topic, stuck on 1 point.

everything below working with exception of habtm zip data.

here code:

<?php ($i = 1; $i <= 3; $i++) { // 3 fields @ time ?>       <?php echo $this->form->input('plan.' . $i . '.plan_detail_id', array(     'options' => $plans_list,     'type'    => 'select',     'empty'   => '-- select plan detail --',     'label'   => 'select plan detail' )); ?>      <?php echo $this->form->input('plan.' . $i . '.monthly_cost', array('label' => 'monthly cost')); ?>     <?php echo $this->form->input('plan.' . $i . '.dental_cost', array('label' => 'dental cost')); ?>     <?php echo $this->form->input('plan.' . $i . '.age_id', array('label' => 'select age range', 'empty' => '-- select age range --')); ?>     <?php echo $this->form->input('plan.' . $i . '.applicant_id', array('label' => 'applicant type', 'empty' => '-- select applicant type  --')); ?>     <?php echo $this->form->input('plan.' . $i . '.state_id', array('label' => 'select state', 'empty' => '-- select state --')); ?>     <?php echo $this->form->input('"$i".zip', array(     'type'     => 'select',     'multiple' => 'true',     'label'    => 'select zips' )); <?php } // end for() ?> 

my controller action follows:

function bulk_add() {     if (!empty($this->data)) {         $this->plan->create();         if ($this->plan->saveall($this->data, array('validate' => 'false'))) {             $this->session->setflash(__('the plan has been saved', true));             $this->redirect(array('action' => 'index'));         } else {             $this->session->setflash(__('the plan not saved. please, try again.', true));         }     }     $ages = $this->plan->age->find('list', array('order' => array('age.name asc')));     $applicants = $this->plan->applicant->find('list', array('order' => array('applicant.name asc')));     $states = $this->plan->state->find('list', array('order' => array('state.name asc')));     $zips = $this->plan->zip->find('list', array('order' => array('zip.title asc')));      $this->set(compact('plandetails', 'ages', 'applicants', 'states', 'zips'));      $plans_list = array();     $plans = $this->plan->plandetail->find('all', array('order' => array('plandetail.name asc')));     foreach ($plans $row) {         $plans_list["{$row['plandetail']['id']}"] = "{$row['plandetail']['name']} - {$row['plandetailnote']['name']}";     }     $this->set('plans_list', $plans_list); } 

day 3 : )

i cannot array (with multiple entries) not indexed numerically. , keyed array required saveall() on multiple tables work properly.

i have complete data dump below numeric indexed array, , somehow needs indexed keys (i can work correctly on single record insert)..

my view bulk_add

<?php ($i = 1; $i <= 2; $i++) { ?> <table>   <tr>   <td><?php echo $this->form->input("$i.plan_detail_id", array(     'options' => $plans_list,     'type'    => 'select',     'empty'   => '-- select plan detail --',     'label'   => 'select plan detail' )); ?></td>     <td><?php echo $this->form->input("$i.monthly_cost", array('label' => 'monthly cost')); ?></td>     <td><?php echo $this->form->input("$i.dental_cost", array('label' => 'vision cost')); ?></td>     <td><?php echo $this->form->input("$i.age_id", array('label' => 'select age range', 'empty' => '-- select age range --')); ?></td>     <td><?php echo $this->form->input("$i.applicant_id", array('label' => 'applicant type', 'empty' => '-- select applicant type  --')); ?></td>     <td><?php echo $this->form->input("$i.state_id", array('label' => 'select state', 'empty' => '--   select state --')); ?></td>     <td>      <?php echo $this->form->input("$i.zip", array('multiple' => 'true')); ?> </td>   </tr> </table> <?php } // end for() ?> <?php echo $this->form->end(__('submit', true)); ?> 

my controller code:

function bulk_add() {     if (!empty($this->data)) {         $this->plan->create();         if ($this->plan->saveall($this->data, array('atomic' => 'false'))) {             // debug             debug($this->data);             $this->session->setflash(__('the plan has been saved', true));             $this->redirect(array('action' => 'index'));         } else {             $this->session->setflash(__('the plan not saved. please, try again.', true));         }     }     $ages = $this->plan->age->find('list', array('order' => array('age.name asc')));     $applicants = $this->plan->applicant->find('list', array('order' => array('applicant.name  asc')));     $states = $this->plan->state->find('list', array('order' => array('state.name asc')));  $zips = $this->plan->zip->find('list', array('order' => array('zip.title asc')));     $this->set(compact('plandetails', 'ages', 'applicants', 'states', 'zips'));      $plans_list = array();     $plans = $this->plan->plandetail->find('all', array('order' => array('plandetail.name asc')));     foreach ($plans $row) {         $plans_list["{$row['plandetail']['id']}"] = "{$row['plandetail']['name']} - {$row['plandetailnote']['name']}";     }     $this->set('plans_list', $plans_list); } 

here debug dump:

array ( [plan] => array     (         [1] => array             (                 [plan_detail_id] => 36                 [monthly_cost] => 0                 [dental_cost] => 0                 [age_id] => 14                 [applicant_id] => 1                 [state_id] => 1             )          [2] => array             (                 [plan_detail_id] => 36                 [monthly_cost] => 0                 [dental_cost] => 0                 [age_id] => 2                 [applicant_id] => 4                 [state_id] => 1             )      )  [1] => array     (         [1] => array             (                 [zip] => array                     (                         [0] => 487                         [1] => 486                         [2] => 485                         [3] => 484                         [4] => 483                     )              )      )  [2] => array     (         [2] => array             (                 [zip] => array                     (                         [0] => 485                         [1] => 484                         [2] => 483                     )              )      ) 

)


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -