Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Fatal error: Uncaught Error: Call to a member function getData() Boa tarde senhores, estou enfrentando um problema ao chamar o formulário do onInputDialog, não sei como chamr o valor enviado. Tentei $data2 = $this->form2->getData(); porém dá error Fatal error: Uncaught Error: Call to a member function getData() on null in C:xampphtdocsacra5appcontroldadosAlertaEncomendaList.class.php:272 Stack trace: #0 [internal function]: AlertaEncomendaList->o...
PA
Fatal error: Uncaught Error: Call to a member function getData()  
Boa tarde senhores, estou enfrentando um problema ao chamar o formulário do onInputDialog, não sei como chamr o valor enviado.
Tentei $data2 = $this->form2->getData(); porém dá error

Fatal error: Uncaught Error: Call to a member function getData() on null in C:xampphtdocsacra5appcontroldadosAlertaEncomendaList.class.php:272 Stack trace: #0 [internal function]: AlertaEncomendaList->onConfirm1(Array) #1 C:xampphtdocsacra5libadianticontrolTPage.php(51): call_user_func(Array, Array) #2 C:xampphtdocsacra5libadianticontrolTPage.php(205): AdiantiControlTPage->run() #3 C:xampphtdocsacra5libadiantibaseAdiantiStandardListTrait.php(503): AdiantiControlTPage->show() #4 C:xampphtdocsacra5libadiantibaseAdiantiStandardListTrait.php(503): AdiantiBaseTStandardList->show() #5 C:xampphtdocsacra5libadianticoreAdiantiCoreApplication.php(64): AlertaEncomendaList->show(Array) #6 C:xampphtdocsacra5engine.php(23): AdiantiCoreAdiantiCoreApplication::run(true) #7 C:xampphtdocsacra5engine.php(65): TApplication::run(true) #8 {main} thrown in C:xampphtdocsacra5appcontroldadosAlertaEncomendaList.class.php on line 272


Segue abaixo o código:


  1. <?php
  2. class AlertaEncomendaList extends TStandardList
  3. {
  4.     protected $form;     // registration form
  5.     protected $datagrid// listing
  6.     protected $pageNavigation;
  7.     protected $estabelecimento;
  8.     
  9.     // trait with onReload, onSearch, onDelete...
  10.     use Adianti\Base\AdiantiStandardListTrait;
  11.     
  12.     /**
  13.      * Class constructor
  14.      * Creates the page, the form and the listing
  15.      */
  16.     public function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         $this->setDatabase('permission');        // defines the database
  21.         $this->setActiveRecord('Encomenda');       // defines the active record
  22.         $this->addFilterField('name''like''name'); // filter field, operator, form field
  23.         $this->setDefaultOrder('id''desc');  // define the default order
  24.         $this->estabelecimento TSession::getValue('userunitid');
  25.         
  26.         // creates the form
  27.         $this->form = new BootstrapFormBuilder('form_lista_apartamentos');
  28.         $this->form->setFormTitle('Alerta de encomendas');
  29.         $criterio = new TCriteria;
  30.         $criterio->add(new TFilter('fk_id_system_unit','='$this->estabelecimento));
  31.         $apartamento = new TDBUniqueSearch('fk_id_unidade''permission''Unidade''id''nome''nome'$criterio);
  32.         $apartamento->setSize('85%');
  33.         $this->form->addFields( [new TLabel('Apartamento')], [$apartamento] );
  34.         // add form actions
  35.         $this->form->addAction('Alerta de encomenda',  new TAction([$this'onSave']), 'fa:plus white')->class 'btn btn-sm btn-success';
  36.         
  37.         // keep the form filled with the search data
  38.         $this->form->setDataTSession::getValue('StandardDataGridView_filter_data') );
  39.         
  40.         // creates the DataGrid
  41.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  42.         $this->datagrid->width "100%";
  43.         
  44.         // creates the datagrid columns
  45.         $col_dt_chegada   = new TDataGridColumn('data_hora_chegada''Data de chegada''center');
  46.         $col_dt_entrega  = new TDataGridColumn('data_hora_entrega''Data de entrega''center');
  47.         $col_apartamento  = new TDataGridColumn('fk_id_unidade''Apartamento''center');
  48.         $col_status = new TDataGridColumn('fk_id_system_unit''Status''center');
  49.         
  50.         $this->datagrid->addColumn($col_dt_chegada);
  51.         $this->datagrid->addColumn($col_dt_entrega);
  52.         $this->datagrid->addColumn($col_apartamento);
  53.         $this->datagrid->addColumn($col_status);
  54.         $col_dt_chegada->setTransformer( function($value$object$row) {
  55.             $data TDate::date2br($value );
  56.             return $data;
  57.         });
  58.         //Formata os campos da encomenda da coluna
  59.         $col_status->setTransformer( function($value$object$row) {
  60.             $class = ($value=='N') ? 'success' 'danger';
  61.             $label = ($value=='N') ? 'A caminho' 'Na portaria';
  62.             $div = new TElement('span');
  63.             $div->class="label label-{$class}";
  64.             $div->style="text-shadow:none; font-size:12px; font-weight:lighter";
  65.             $div->add($label);
  66.             return $div;
  67.         });
  68.         // create EDIT action
  69.         $action_edit = new TDataGridAction(array($this'onInputDialog'));
  70.         $action_edit->setLabel('Entrega');
  71.         $action_edit->setImage('fa:envelope-o blue fa-lg');
  72.         $action_edit->setField('id');
  73.         $this->datagrid->addAction($action_edit);
  74.         $col_apartamento->setTransformer( function($value$object$row) {
  75.             
  76.             $unidade = new Unidade($value);
  77.             return $unidade->nome;
  78.         });
  79.         $col_dt_chegada->setAction( new TAction([$this'onReload']), ['order' => 'data_hora_entrega']);
  80.         $col_apartamento->setAction( new TAction([$this'onReload']), ['order' => 'fk_id_system_unit']);
  81.         $col_status->setAction( new TAction([$this'onReload']), ['order' => 'login']);
  82.         
  83.         // create the datagrid model
  84.         $this->datagrid->createModel();
  85.         
  86.         // creates the page navigation
  87.         $this->pageNavigation = new TPageNavigation;
  88.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  89.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  90.         
  91.         // creates the page structure using a table
  92.         $vbox = new TVBox;
  93.         $vbox->style 'width: 100%';
  94.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  95.         $vbox->add($this->form);
  96.         $vbox->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation));
  97.         
  98.         // add the table inside the page
  99.         parent::add($vbox);
  100.     }
  101.     public function onSave(){
  102.         try {
  103.             TTransaction::open('permission');
  104.             $data $this->form->getData('Encomenda');
  105.             $object = new Encomenda;
  106.             $object->fk_id_system_unit $this->estabelecimento;
  107.             $object->fk_id_unidade $data->fk_id_unidade;
  108.             $object->data_hora_chegada date('Y-m-d H:i:s');
  109.             $object->store();
  110.             new TMessage('info''Registro salvo com sucesso!');
  111.             TTransaction::close();
  112.             $this->onReload(); // recarregar a página
  113.         } catch (Exception $e) {
  114.             new TMessage('error'$e->getMessage());
  115.         }
  116.     }
  117.     public function onReload($param NULL)
  118.     {
  119.         try
  120.         {
  121.             // open a transaction with database 'permission'
  122.             TTransaction::open('permission');
  123.             
  124.             $repository = new TRepository('Encomenda');
  125.             $limit 10;
  126.             // creates a criteria
  127.             $criteria = new TCriteria;
  128.             
  129.             // default order
  130.             if (empty($param['order']))
  131.             {
  132.                 $param['order'] = 'id';
  133.                 $param['direction'] = 'desc';
  134.             }
  135.             $criteria->setProperties($param); // order, offset
  136.             $criteria->setProperty('limit'$limit);
  137.             // load the objects according to criteria
  138.             $objects $repository->load($criteriaFALSE);
  139.             
  140.             if (is_callable($this->transformCallback))
  141.             {
  142.                 call_user_func($this->transformCallback$objects$param);
  143.             }
  144.             
  145.             $this->datagrid->clear();
  146.             if ($objects)
  147.             {
  148.                 // iterate the collection of active records
  149.                 foreach ($objects as $object)
  150.                 {
  151.                     if($object->fk_id_system_unit == $this->estabelecimento){
  152.                        // add the object inside the datagrid
  153.                         $this->datagrid->addItem($object); 
  154.                     } 
  155.                 }
  156.             }
  157.             
  158.             // reset the criteria for record count
  159.             $criteria->resetProperties();
  160.             $count$repository->count($criteria);
  161.             
  162.             $this->pageNavigation->setCount($count); // count of records
  163.             $this->pageNavigation->setProperties($param); // order, page
  164.             $this->pageNavigation->setLimit($limit); // limit
  165.             
  166.             // close the transaction
  167.             TTransaction::close();
  168.             $this->loaded true;
  169.         }
  170.         catch (Exception $e// in case of exception
  171.         {
  172.             // shows the exception error message
  173.             new TMessage('error'$e->getMessage());
  174.             // undo all pending operations
  175.             TTransaction::rollback();
  176.         }
  177.     }
  178.     /*public function btn_action($param){
  179.         
  180.         $form2 = new TQuickForm('input_form');
  181.         $form2->style = 'padding:20px';
  182.         
  183.         $confirmar = new TCheckGroup('confirmar');
  184.         $options = [1=>''];
  185.         $confirmar->addItems($options);
  186.         $confirmar->setLayout('horizontal');
  187.         $form2->addQuickField('Confirmar entrega ', $confirmar);
  188.         $key = $param['key'];
  189.             echo $key;
  190.         
  191.        $form2->addQuickAction('Confirmar', new TAction(array($this, 'onConfirm1')), 'fa:save green');
  192.         // show the input dialog
  193.         new TInputDialog('Confirmar entrega ', $form2);
  194.     }*/
  195.     public function onInputDialog$param )
  196.     {
  197.         TTransaction::open('permission');
  198.         $confirmar = new TCheckGroup('confirm');
  199.         //$amount = new TEntry('amount');
  200.         $confirmar->setValue($param['key']);
  201.         $options = [1=>''];
  202.         $confirmar->addItems($options);
  203.         $confirmar->setLayout('horizontal');
  204.         
  205.         $repository = new TRepository('Encomenda');
  206.         $criteria = new TCriteria;
  207.         $criteria->add(new TFilter('id','='$param['key']));
  208.         $objects $repository->load($criteriaFALSE);
  209.         // iterate the collection of active records
  210.         foreach ($objects as $object)
  211.         {
  212.             $form2 = new TForm('input_form');
  213.             $form2->style 'padding:20px';
  214.             
  215.             $table = new TTable;
  216.             $table->addRowSet( new TLabel('Confirmar entrega '), $confirmar );
  217.             //$table->addRowSet( $lbl = new TLabel('Amount: '), $amount );
  218.             //$lbl->setFontColor('red');
  219.             
  220.             //$form2->setFields(array($confirmar, $amount));
  221.             $form2->add($table);
  222.             
  223.             $casa = new Unidade($object->fk_id_unidade);
  224.             $casa->nome;
  225.             // show the input dialog
  226.             $action = new TAction(array($this'onConfirm1'));
  227.             $action->setParameter('stay-open'1);
  228.             new TInputDialog('Confirmar entrega em '.$casa->nome$form2$action'Confirmar');
  229.         }
  230.         TTransaction::close();
  231.     }
  232.     public function onConfirm1($param){
  233.         try {
  234.             TTransaction::open('permission');
  235.             $data2 $this->form2->getData();
  236.             //if($data->confirm){
  237.                 $object_entrega = new Encomenda($param['key']);
  238.                 $object_entrega->data_hora_entrega date('Y-m-d H:i:s');
  239.            // }
  240.             TTransaction::close();
  241.             // recarregar a página
  242.             //$this->onReload();
  243.         } catch (Exception $e) {
  244.             new TMessage('error'$e->getMessage());
  245.         }
  246.     }
  247. }

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)


NR

Ao criar uma variável dentro de uma função ela só será acessível dentro desta. Eu usaria as 2 funções(onInputDialog e onConfirm1) como estáticas e pegaria os dados do form através da variável $param.
  1. <?php
  2. public static function onConfirm1($param){
  3.         try {
  4.             TTransaction::open('permission');
  5.             var_dump($param);
  6. ?>

Mais informações sobre escopo de variáveis:
https://www.php.net/manual/pt_BR/language.variables.scope.php