TDBMultiSearch não grava Dados Pessoal estou usando TDBMultiSearch para gravar os municipios de carregamento da da MDF-e mas não esta gravando, fica em branco, estou tentando gravar em uma tabela que se chama "Carregamento". O que pode ser ? Form: Store() ...
RA
TDBMultiSearch não grava Dados  
Pessoal estou usando TDBMultiSearch para gravar os municipios de carregamento da da MDF-e mas não esta gravando, fica em branco, estou tentando gravar em uma tabela que se chama "Carregamento". O que pode ser ?

Form:
 
  1. <?php
  2. ...
  3. $Carregamento= new TDBMultiSearch('Municipio_ID', 'mdfe', 'municipio', 'ID_Municipio','Nome', 'UF');
  4. .
  5. .
  6. .
  7. ?>


Store()
 
  1. <?php
  2. public function store()
  3. {
  4. // store the object itself
  5. parent::store();
  6. // delete the related Carregamento objects
  7. $criteria = new TCriteria;
  8. $criteria->add(new TFilter('mdfe_id', '=', $this->id));
  9. $repository = new TRepository('Carregamento');
  10. $repository->delete($criteria);
  11. // store the related Carregamento objects
  12. if ($this->carregamentos)
  13. {
  14. foreach ($this->carregamentos as $carregamento)
  15. {
  16. unset($carregamento->id);
  17. $carregamento->mdfe_id = $this->id;
  18. $carregamento->store();
  19. }
  20. }
  21. ...
  22. ?>

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (5)


RA

No onSave esta assim:

 
  1. <?php
  2. /**
  3. * Save form data
  4. * @param $param Request
  5. */
  6. public function onSave( $param )
  7. {
  8. try
  9. {
  10. TTransaction::open('mdfe'); // open a transaction
  11. /**
  12. // Enable Debug logger for SQL operations inside the transaction
  13. TTransaction::setLogger(new TLoggerSTD); // standard output
  14. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  15. **/
  16. $this->form->validate(); // validate form data
  17. $data = $this->form->getData(); // get form data as array
  18. $object = new Mdfe; // create an empty object
  19. $object->fromArray( (array) $data); // load the object with data
  20. $object->store(); // save the object
  21. // get the generated ID_Mdfe
  22. $data->ID_Mdfe = $object->ID_Mdfe;
  23. $this->form->setData($data); // fill form data
  24. TTransaction::close(); // close the transaction
  25. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  26. }
  27. catch (Exception $e) // in case of exception
  28. {
  29. new TMessage('error', $e->getMessage()); // shows the exception error message
  30. $this->form->setData( $this->form->getData() ); // keep form data
  31. TTransaction::rollback(); // undo all pending operations
  32. }
  33. }
  34. ?>
NR

A sua função onSave não está fazendo o tratamento da composição.

Você vai precisar fazer o foreach dos municípios e adicionar os itens, antes de chamar a função store:
 
  1. <?php
  2. foreach ($data->Municipio_ID as $municipio_id)
  3. {
  4. $carregamento = new Carregamento();
  5. $carregamento->Municipio_ID = $municipio_id; //conferir nome do atributo
  6. $object->addCarregamento($carregamento); //conferir nome da função
  7. }
  8. ?>
RA

Nataniel Rabaioli Não funcionou.
NR

Como ficou a onSave?
RA

Nataniel Rabaioli não entendi esse foreach no onSave, pois já não é feito no model em Store() ?

 
  1. <?php
  2. public function store()
  3. {
  4. // store the object itself
  5. parent::store();
  6. // delete the related Carregamento objects
  7. $criteria = new TCriteria;
  8. $criteria->add(new TFilter('mdfe_id', '=', $this->id));
  9. $repository = new TRepository('Carregamento');
  10. $repository->delete($criteria);
  11. // store the related Carregamento objects
  12. if ($this->carregamentos)
  13. {
  14. foreach ($this->carregamentos as $carregamento)
  15. {
  16. unset($carregamento->id);
  17. $carregamento->mdfe_id = $this->id;
  18. $carregamento->store();
  19. }
  20. }
  21. ...
  22. ?>