Erro ao redirecionar form para um FormView depois de Salvar Bom dia, preciso redirecionar uma página para um FormView depois de salvar o formulário. Estou utilizando o seguinte código no onSave: E estou recebendo o erro: Método AdiantiControlTAction::__construct deve receber um parâmetro do tipo Callback Verifique se a a�...
ET
Erro ao redirecionar form para um FormView depois de Salvar  
Bom dia, preciso redirecionar uma página para um FormView depois de salvar o formulário. Estou utilizando o seguinte código no onSave:
 
  1. <?php
  2. $action = new TAction(array('ReciboFormView', 'onReload'));
  3. new TMessage('info', $message, $action);
  4. ?>

E estou recebendo o erro: Método AdiantiControlTAction::__construct deve receber um parâmetro do tipo Callback
Verifique se a ação (ReciboFormView::onReload) existe

Alguém sabe como posso resolver isso?
Desde já agradeço a ajuda.

Código do Form:

 
  1. <?php
  2. /**
  3. * ReciboForm Form
  4. * @author <your name here>
  5. */
  6. class ReciboForm extends TPage
  7. {
  8. protected $form; // form
  9. /**
  10. * Form constructor
  11. * @param $param Request
  12. */
  13. public function __construct( $param )
  14. {
  15. parent::__construct();
  16. // creates the form
  17. $this->form = new BootstrapFormBuilder('form_Recibo');
  18. $this->form->setFormTitle('Recibo');
  19. $this->form->setClientValidation(true);
  20. // create the form fields
  21. $id = new TEntry('id');
  22. $recebi_de = new TEntry('recebi_de');
  23. $cpf_cnpj = new TEntry('cpf_cnpj');
  24. $valor = new TEntry('valor');
  25. $dt_emissao = new TDate('dt_emissao');
  26. $referente_a = new TEntry('referente_a');
  27. // add the fields
  28. $this->form->addFields( [ new TLabel('Código') ], [ $id ] );
  29. $this->form->addFields( [ new TLabel('Recebi de*', '#FF0000') ], [ $recebi_de ], [ new TLabel('Cpf ou Cnpj') ], [ $cpf_cnpj ] );
  30. $this->form->addFields( [ new TLabel('Valor R$*', '#FF0000') ], [ $valor ], [ new TLabel('Na data') ], [ $dt_emissao ] );
  31. $this->form->addFields( [ new TLabel('Referente a') ], [ $referente_a ] );
  32. $recebi_de->addValidation('Recebi de', new TRequiredValidator);
  33. $valor->addValidation('Valor R$', new TRequiredValidator);
  34. // set sizes
  35. $id->setSize('100');
  36. $recebi_de->setSize('100%');
  37. $cpf_cnpj->setSize('100%');
  38. $valor->setSize('100%');
  39. $dt_emissao->setSize('100%');
  40. $referente_a->setSize('100%');
  41. $recebi_de->setMaxLength(100);
  42. $cpf_cnpj->setMaxLength(20);
  43. $referente_a->setMaxLength(100);
  44. $valor->setNumericMask(2, ',', '.', true);
  45. $dt_emissao->setDatabaseMask('yyyy-mm-dd');
  46. $dt_emissao->setMask('dd/mm/yyyy');
  47. if (!empty($id))
  48. {
  49. $id->setEditable(FALSE);
  50. }
  51. /** samples
  52. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  53. $fieldX->setSize( '100%' ); // set size
  54. **/
  55. // create the form actions
  56. $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:save');
  57. $btn->class = 'btn btn-sm btn-primary';
  58. $this->form->addActionLink(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
  59. // vertical box container
  60. $container = new TVBox;
  61. $container->style = 'width: 100%';
  62. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  63. $container->add($this->form);
  64. parent::add($container);
  65. }
  66. /**
  67. * Save form data
  68. * @param $param Request
  69. */
  70. public function onSave( $param )
  71. {
  72. try
  73. {
  74. TTransaction::open('loja'); // open a transaction
  75. /**
  76. // Enable Debug logger for SQL operations inside the transaction
  77. TTransaction::setLogger(new TLoggerSTD); // standard output
  78. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  79. **/
  80. $this->form->validate(); // validate form data
  81. $data = $this->form->getData(); // get form data as array
  82. $object = new Recibo; // create an empty object
  83. $object->fromArray( (array) $data); // load the object with data
  84. $object->store(); // save the object
  85. // get the generated id
  86. $data->id = $object->id;
  87. $this->form->setData($data); // fill form data
  88. TTransaction::close(); // close the transaction
  89. $message = 'Registro salvo';
  90. $action = new TAction(array('ReciboFormView', 'onReload'));
  91. new TMessage('info', $message, $action);
  92. //new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
  93. }
  94. catch (Exception $e) // in case of exception
  95. {
  96. new TMessage('error', $e->getMessage()); // shows the exception error message
  97. $this->form->setData( $this->form->getData() ); // keep form data
  98. TTransaction::rollback(); // undo all pending operations
  99. }
  100. }
  101. /**
  102. * Clear form data
  103. * @param $param Request
  104. */
  105. public function onClear( $param )
  106. {
  107. $this->form->clear(TRUE);
  108. }
  109. /**
  110. * Load object to form data
  111. * @param $param Request
  112. */
  113. public function onEdit( $param )
  114. {
  115. try
  116. {
  117. if (isset($param['key']))
  118. {
  119. $key = $param['key']; // get the parameter $key
  120. TTransaction::open('loja'); // open a transaction
  121. $object = new Recibo($key); // instantiates the Active Record
  122. $this->form->setData($object); // fill the form
  123. TTransaction::close(); // close the transaction
  124. }
  125. else
  126. {
  127. $this->form->clear(TRUE);
  128. }
  129. }
  130. catch (Exception $e) // in case of exception
  131. {
  132. new TMessage('error', $e->getMessage()); // shows the exception error message
  133. TTransaction::rollback(); // undo all pending operations
  134. }
  135. }
  136. }
  137. ?>

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 (1)


RL

Falta criar o método onReload na classe ReciboForm