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

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (1)


RL

Falta criar o método onReload na classe ReciboForm