Foreach inside if Cakephp

Asked

Viewed 67 times

1

I have an A table that stores an item, and in this table, I have a related B that may have several items aggregated to an item in table A.

Follow the if code:

if ($this->ClientePagamento->save($valor_pagar)) {
            $this->Session->setFlash('Valor adicionado com Sucesso');
            $id_valor = $this->ClientePagamento->id;
            foreach($moedas_ativas as $moeda){                    
                $itens_referentes = array(
                    'cliente_pagamento_id' => $id_valor,
                    'valor' => $moeda[key($moeda)]['valor_reais'],                                                
                );
                $this->ClientePagamentoItem->save($itens_referentes);
            }  

In this foreach are the items that should be saved, but the foreach only runs once and ends up saving only the first item, being that in the array has more than 1 item. That’s semantic error or something?

  • I believe we missed one create before saving something like this: $this->ClientePagamentoItem->create();.

  • That’s right, thanks Paul..

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.