Tuesday, April 7, 2015

Re: Still having trouble with saving BelongsToMany data

I think you should better jump into the IRC channel so we can debug step by step your code. Using google groups for debugging problems has proven to be difficult. 

On Monday, April 6, 2015 at 10:22:41 PM UTC+2, Mauri Cabrera wrote:

This is my add function and its add.ctp form Im following the google group and this repository so you know how my other baked entities tables controllers are

public function add()      {          $sobre = $this->Sobres->newEntity();          if ($this->request->is('post')) {              // Reset indexes on the associated data         $this->request->data['products'] = array_values($this->request->data['products']);        $sobre = $this->Sobres->patchEntity($sobre, $this->request->data,                                              ['associated' => ['Products._joinData']]);  //          $sobre = $this->Sobres->patchEntity($sobre, $this->request->data,['associated'=>['products._joinData']]);  //            $sobre->dirty('products._joinData',true);              if ($this->Sobres->save($sobre)) {                  $this->Flash->success('The sobre has been saved.');  //                return $this->redirect(['action' => 'index']);              } else {                  $this->Flash->error('The listing could not be saved. Please, try again.');              }          }          $users = $this->Sobres->Users->find('list');          $clients = $this->Sobres->Clients->find('list');          $products = $this->Sobres->Products->find('list');          $this->set(compact('sobre', 'users', 'clients', 'products'));          $this->set('_serialize', ['sobre']);      }  
<div class="sobres form large-10 medium-9 columns">      <?= $this->Form->create($sobre); ?>      <fieldset>          <legend><?= __('Add Sobre') ?></legend>          <?php                   echo $this->Form->input('user_id', ['options' => $users]);              echo $this->Form->input('client_id', ['options' => $clients]);              echo $this->Form->input('total');                if(!empty($products)){                  $i =0;                  foreach( $products as $k => $pro){                              echo $this->Form->input('products.'.$i.'.id',['type'=>'checkbox','value'=>$k,'label'=>$pro]);                               echo $this->Form->input('products.'.$i.'._joinData.quantity');   //                              echo $this->Form->input('products.'.$i.'.name',['type'=>'hidden','value'=>$pro]);  //                            echo $this->Form->input('products.'.$i.'.price',['type'=>'hidden','value'=>$pro]);                              $i++;                          }                          }              ?>      </fieldset>      <?= $this->Form->button(__('Submit')) ?>      <?= $this->Form->end() ?>  </div>  

PLEASE HELP!!!

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: