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
Model Filial.class.php
Tambem gostaria de efetuar um filtro de unit_id na busca do tdbseekbutton, pelo tcriteria.
Alguem poderia me ajudar?
Control FilialForm.class.php
- <?php
- /**
- * FilialForm Form
- * @author <your name here>
- */
- class FilialForm extends TPage
- {
- protected $form; // form
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Filial');
- $this->form->setFormTitle('Filial');
- // create the form fields
- $id = new TEntry('id');
- $unit_id = new TEntry('unit_id');
- $empresa_id = new ">TDBSeekButton('empresa_id', 'conexaopgsql', 'EmpresaSeek', 'Empresa', 'emp_razao', 'id', 'emp_razao');
- //$empresa_id = new TDBSeekButton('empresa_id', 'conexaopgsql', $this->form->getName(), 'Empresa', 'emp_razao', 'empresa_id', 'emp_razao');
- $fil_razao = new TEntry('fil_razao');
- $fil_fantasia = new TEntry('fil_fantasia');
- $fil_cnpj = new TEntry('fil_cnpj');
- $fil_cpf = new TEntry('fil_cpf');
- $fil_cei = new TEntry('fil_cei');
- $cod_cid = new TEntry('cod_cid');
- $fil_cep = new TEntry('fil_cep');
- $fil_endereco = new TEntry('fil_endereco');
- $fil_bairro = new TEntry('fil_bairro');
- $fil_fone = new TEntry('fil_fone');
- $fil_status = new TEntry('fil_status');
- // add the fields
- $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
- $this->form->addFields( [ new TLabel('Unit Id') ], [ $unit_id ] );
- $this->form->addFields( [ new TLabel('Empresa Id') ], [ $empresa_id ] );
- $this->form->addFields( [ new TLabel('Fil Razao') ], [ $fil_razao ] );
- $this->form->addFields( [ new TLabel('Fil Fantasia') ], [ $fil_fantasia ] );
- $this->form->addFields( [ new TLabel('Fil Cnpj') ], [ $fil_cnpj ] );
- $this->form->addFields( [ new TLabel('Fil Cpf') ], [ $fil_cpf ] );
- $this->form->addFields( [ new TLabel('Fil Cei') ], [ $fil_cei ] );
- $this->form->addFields( [ new TLabel('Cod Cid') ], [ $cod_cid ] );
- $this->form->addFields( [ new TLabel('Fil Cep') ], [ $fil_cep ] );
- $this->form->addFields( [ new TLabel('Fil Endereco') ], [ $fil_endereco ] );
- $this->form->addFields( [ new TLabel('Fil Bairro') ], [ $fil_bairro ] );
- $this->form->addFields( [ new TLabel('Fil Fone') ], [ $fil_fone ] );
- $this->form->addFields( [ new TLabel('Fil Status') ], [ $fil_status ] );
- // set sizes
- $id->setSize('100%');
- $unit_id->setSize('100%');
- $empresa_id->setSize('100%');
- $fil_razao->setSize('100%');
- $fil_fantasia->setSize('100%');
- $fil_cnpj->setSize('100%');
- $fil_cpf->setSize('100%');
- $fil_cei->setSize('100%');
- $cod_cid->setSize('100%');
- $fil_cep->setSize('100%');
- $fil_endereco->setSize('100%');
- $fil_bairro->setSize('100%');
- $fil_fone->setSize('100%');
- $fil_status->setSize('100%');
- if (!empty($id))
- {
- $id->setEditable(FALSE);
- }
- /** samples
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( '100%' ); // set size
- **/
- // create the form actions
- $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addAction(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Save form data
- * @param $param Request
- */
- public function onSave( $param )
- {
- try
- {
- TTransaction::open('conexaopgsql'); // open a transaction
- /**
- // Enable Debug logger for SQL operations inside the transaction
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- **/
- $this->form->validate(); // validate form data
- $data = $this->form->getData(); // get form data as array
- $object = new Filial; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- // get the generated id
- $data->id = $object->id;
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear(TRUE);
- }
- /**
- * Load object to form data
- * @param $param Request
- */
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('conexaopgsql'); // open a transaction
- $object = new Filial($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear(TRUE);
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
- ?>
Model Filial.class.php
- <?php
- /**
- * Filial Active Record
- * @author <your-name-here>
- */
- class Filial extends TRecord
- {
- const TABLENAME = 'public.filial';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'serial'; // {max, serial}
- private $empresa;
- /**
- * Constructor method
- */
- public function __construct($id = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct($id, $callObjectLoad);
- parent::addAttribute('unit_id');
- parent::addAttribute('empresa_id');
- parent::addAttribute('fil_razao');
- parent::addAttribute('fil_fantasia');
- parent::addAttribute('fil_cnpj');
- parent::addAttribute('fil_cpf');
- parent::addAttribute('fil_cei');
- parent::addAttribute('cod_cid');
- parent::addAttribute('fil_cep');
- parent::addAttribute('fil_endereco');
- parent::addAttribute('fil_bairro');
- parent::addAttribute('fil_fone');
- parent::addAttribute('fil_status');
- }
- /**
- * Method set_empresa
- * Sample of usage: $filial->empresa = $object;
- * @param $object Instance of Empresa
- */
- public function set_empresa(Empresa $object)
- {
- $this->empresa = $object;
- $this->empresa_id = $object->id;
- }
- /**
- * Method get_empresa
- * Sample of usage: $filial->empresa->attribute;
- * @returns Empresa instance
- */
- public function get_empresa()
- {
- // loads the associated object
- if (empty($this->empresa))
- $this->empresa = new Empresa($this->empresa_id);
- // returns the associated object
- return $this->empresa;
- }
- }
- ?>
Confirme se o arquivo TWindow.php está em lib/adianti/control/
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);
?>