Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TDBSeekButton - Erro na hora de carregar a pagina. Estou tentando usar o componente TDBSeekButton porem não estou conseguindo finaliza-lo. Tambem gostaria de efetuar um filtro de unit_id na busca do tdbseekbutton, pelo tcriteria. Alguem poderia me ajudar? Control FilialForm.class.php ...
BI
TDBSeekButton - Erro na hora de carregar a pagina.  
Estou tentando usar o componente TDBSeekButton porem não estou conseguindo finaliza-lo.
Tambem gostaria de efetuar um filtro de unit_id na busca do tdbseekbutton, pelo tcriteria.
Alguem poderia me ajudar?


Control FilialForm.class.php

  1. <?php
  2. /**
  3.  * FilialForm Form
  4.  * @author  <your name here>
  5.  */
  6. class FilialForm 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.         // creates the form
  19.         $this->form = new BootstrapFormBuilder('form_Filial');
  20.         $this->form->setFormTitle('Filial');
  21.         
  22.         // create the form fields
  23.         $id = new TEntry('id');
  24.         $unit_id = new TEntry('unit_id');
  25.         $empresa_id   = new  ">TDBSeekButton('empresa_id''conexaopgsql''EmpresaSeek''Empresa''emp_razao''id''emp_razao');
  26.         //$empresa_id          = new TDBSeekButton('empresa_id', 'conexaopgsql', $this->form->getName(), 'Empresa', 'emp_razao', 'empresa_id', 'emp_razao');
  27.         $fil_razao = new TEntry('fil_razao');
  28.         $fil_fantasia = new TEntry('fil_fantasia');
  29.         $fil_cnpj = new TEntry('fil_cnpj');
  30.         $fil_cpf = new TEntry('fil_cpf');
  31.         $fil_cei = new TEntry('fil_cei');
  32.         $cod_cid = new TEntry('cod_cid');
  33.         $fil_cep = new TEntry('fil_cep');
  34.         $fil_endereco = new TEntry('fil_endereco');
  35.         $fil_bairro = new TEntry('fil_bairro');
  36.         $fil_fone = new TEntry('fil_fone');
  37.         $fil_status = new TEntry('fil_status');
  38.         // add the fields
  39.         $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  40.         $this->form->addFields( [ new TLabel('Unit Id') ], [ $unit_id ] );
  41.         $this->form->addFields( [ new TLabel('Empresa Id') ], [ $empresa_id ] );
  42.         $this->form->addFields( [ new TLabel('Fil Razao') ], [ $fil_razao ] );
  43.         $this->form->addFields( [ new TLabel('Fil Fantasia') ], [ $fil_fantasia ] );
  44.         $this->form->addFields( [ new TLabel('Fil Cnpj') ], [ $fil_cnpj ] );
  45.         $this->form->addFields( [ new TLabel('Fil Cpf') ], [ $fil_cpf ] );
  46.         $this->form->addFields( [ new TLabel('Fil Cei') ], [ $fil_cei ] );
  47.         $this->form->addFields( [ new TLabel('Cod Cid') ], [ $cod_cid ] );
  48.         $this->form->addFields( [ new TLabel('Fil Cep') ], [ $fil_cep ] );
  49.         $this->form->addFields( [ new TLabel('Fil Endereco') ], [ $fil_endereco ] );
  50.         $this->form->addFields( [ new TLabel('Fil Bairro') ], [ $fil_bairro ] );
  51.         $this->form->addFields( [ new TLabel('Fil Fone') ], [ $fil_fone ] );
  52.         $this->form->addFields( [ new TLabel('Fil Status') ], [ $fil_status ] );
  53.         // set sizes
  54.         $id->setSize('100%');
  55.         $unit_id->setSize('100%');
  56.         $empresa_id->setSize('100%');
  57.         $fil_razao->setSize('100%');
  58.         $fil_fantasia->setSize('100%');
  59.         $fil_cnpj->setSize('100%');
  60.         $fil_cpf->setSize('100%');
  61.         $fil_cei->setSize('100%');
  62.         $cod_cid->setSize('100%');
  63.         $fil_cep->setSize('100%');
  64.         $fil_endereco->setSize('100%');
  65.         $fil_bairro->setSize('100%');
  66.         $fil_fone->setSize('100%');
  67.         $fil_status->setSize('100%');
  68.         if (!empty($id))
  69.         {
  70.             $id->setEditable(FALSE);
  71.         }
  72.         
  73.         /** samples
  74.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  75.          $fieldX->setSize( '100%' ); // set size
  76.          **/
  77.          
  78.         // create the form actions
  79.         $btn $this->form->addAction(_t('Save'), new TAction([$this'onSave']), 'fa:floppy-o');
  80.         $btn->class 'btn btn-sm btn-primary';
  81.         $this->form->addAction(_t('New'),  new TAction([$this'onEdit']), 'fa:eraser red');
  82.         
  83.         // vertical box container
  84.         $container = new TVBox;
  85.         $container->style 'width: 90%';
  86.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  87.         $container->add($this->form);
  88.         
  89.         parent::add($container);
  90.     }
  91.     /**
  92.      * Save form data
  93.      * @param $param Request
  94.      */
  95.     public function onSave$param )
  96.     {
  97.         try
  98.         {
  99.             TTransaction::open('conexaopgsql'); // open a transaction
  100.             
  101.             /**
  102.             // Enable Debug logger for SQL operations inside the transaction
  103.             TTransaction::setLogger(new TLoggerSTD); // standard output
  104.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  105.             **/
  106.             
  107.             $this->form->validate(); // validate form data
  108.             $data $this->form->getData(); // get form data as array
  109.             
  110.             $object = new Filial;  // create an empty object
  111.             $object->fromArray( (array) $data); // load the object with data
  112.             $object->store(); // save the object
  113.             
  114.             // get the generated id
  115.             $data->id $object->id;
  116.             
  117.             $this->form->setData($data); // fill form data
  118.             TTransaction::close(); // close the transaction
  119.             
  120.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  121.         }
  122.         catch (Exception $e// in case of exception
  123.         {
  124.             new TMessage('error'$e->getMessage()); // shows the exception error message
  125.             $this->form->setData$this->form->getData() ); // keep form data
  126.             TTransaction::rollback(); // undo all pending operations
  127.         }
  128.     }
  129.     
  130.     /**
  131.      * Clear form data
  132.      * @param $param Request
  133.      */
  134.     public function onClear$param )
  135.     {
  136.         $this->form->clear(TRUE);
  137.     }
  138.     
  139.     /**
  140.      * Load object to form data
  141.      * @param $param Request
  142.      */
  143.     public function onEdit$param )
  144.     {
  145.         try
  146.         {
  147.             if (isset($param['key']))
  148.             {
  149.                 $key $param['key'];  // get the parameter $key
  150.                 TTransaction::open('conexaopgsql'); // open a transaction
  151.                 $object = new Filial($key); // instantiates the Active Record
  152.                 $this->form->setData($object); // fill the form
  153.                 TTransaction::close(); // close the transaction
  154.             }
  155.             else
  156.             {
  157.                 $this->form->clear(TRUE);
  158.             }
  159.         }
  160.         catch (Exception $e// in case of exception
  161.         {
  162.             new TMessage('error'$e->getMessage()); // shows the exception error message
  163.             TTransaction::rollback(); // undo all pending operations
  164.         }
  165.     }
  166. }
  167. ?>


Model Filial.class.php

  1. <?php
  2. /**
  3.  * Filial Active Record
  4.  * @author  <your-name-here>
  5.  */
  6. class Filial extends TRecord
  7. {
  8.     const TABLENAME 'public.filial';
  9.     const PRIMARYKEY'id';
  10.     const IDPOLICY =  'serial'// {max, serial}
  11.     
  12.     
  13.     private $empresa;
  14.     /**
  15.      * Constructor method
  16.      */
  17.     public function __construct($id NULL$callObjectLoad TRUE)
  18.     {
  19.         parent::__construct($id$callObjectLoad);
  20.         parent::addAttribute('unit_id');
  21.         parent::addAttribute('empresa_id');
  22.         parent::addAttribute('fil_razao');
  23.         parent::addAttribute('fil_fantasia');
  24.         parent::addAttribute('fil_cnpj');
  25.         parent::addAttribute('fil_cpf');
  26.         parent::addAttribute('fil_cei');
  27.         parent::addAttribute('cod_cid');
  28.         parent::addAttribute('fil_cep');
  29.         parent::addAttribute('fil_endereco');
  30.         parent::addAttribute('fil_bairro');
  31.         parent::addAttribute('fil_fone');
  32.         parent::addAttribute('fil_status');
  33.     }
  34.     
  35.     /**
  36.      * Method set_empresa
  37.      * Sample of usage: $filial->empresa = $object;
  38.      * @param $object Instance of Empresa
  39.      */
  40.     public function set_empresa(Empresa $object)
  41.     {
  42.         $this->empresa $object;
  43.         $this->empresa_id $object->id;
  44.     }
  45.     
  46.     /**
  47.      * Method get_empresa
  48.      * Sample of usage: $filial->empresa->attribute;
  49.      * @returns Empresa instance
  50.      */
  51.     public function get_empresa()
  52.     {
  53.         // loads the associated object
  54.         if (empty($this->empresa))
  55.             $this->empresa = new Empresa($this->empresa_id);
  56.     
  57.         // returns the associated object
  58.         return $this->empresa;
  59.     }
  60.     
  61. }
  62. ?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (2)


NR

Confirme se o arquivo TWindow.php está em lib/adianti/control/
LA

Me parece que é no TDBSeekButton, esta configurado errado.

?php
$empresa_id = new TDBSeekButton('empresa_id', 'conexaopgsql', 'form_Filial', 'Empresas', 'emp_razao', 'empresa_id', 'emp_razao', $criteria);
?>

TDBSeekButton($name, $database, $form, $model, $display_field, $receive_key, $receive_display_field, $criteria); Parâmetros: $name (nome do campo no formulário) $database (nome da conexão do banco de dados) $form (nome do formulário) $model (a ser pesquisado)   $display_field (nome do campo a ser pesquisado e mostrado) $receive_key (nome do campo no formulário para receber a chave primária)   $receive_display_field (nome do campo no formulário para receber o 'campo de exibição') $criteria (para adicionar mais filtros)