ET
Object of class Funcionario could not be converted to string
Boa tarde, estou tendo o seguinte erro ao tentar salvar os dados no Form:
Object of class Funcionario could not be converted to string
Segue código:
Object of class Funcionario could not be converted to string
Segue código:
- <?php
- /**
- * FuncionarioForm Form
- * @author <your name here>
- */
- class FuncionarioForm extends TPage
- {
- protected $form; // form
- use Adianti\Base\AdiantiFileSaveTrait;
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Funcionario');
- $this->form->setFormTitle('Funcionario');
- // create the form fields
- $id = new TEntry('id');
- $nome = new TEntry('nome');
- $rg = new TEntry('rg');
- $cpf = new TEntry('cpf');
- $pis = new TEntry('pis');
- $naturalidade_id = new TDBUniqueSearch('naturalidade_id', 'microerp', 'Naturalidade', 'id', 'naturalidade');
- $sexo_id = new TDBUniqueSearch('sexo_id', 'microerp', 'Sexo', 'id', 'sexo');
- $data_nascimento = new TDate('data_nascimento');
- $telefone = new TEntry('telefone');
- $celular = new TEntry('celular');
- $uf_id = new TDBUniqueSearch('uf_id', 'microerp', 'Uf', 'id', 'uf');
- $cidade_id = new TDBUniqueSearch('cidade_id', 'microerp', 'Cidade', 'id', 'nome');
- $bairro_id = new TDBUniqueSearch('bairro_id', 'microerp', 'Bairro', 'id', 'bairro');
- $logradouro = new TDBUniqueSearch('logradouro', 'microerp', 'Logradouro', 'id', 'logradouro');
- $numero = new TEntry('numero');
- $complemento = new TEntry('complemento');
- $cep_id = new TDBUniqueSearch('cep_id', 'microerp', 'Cep', 'id', 'cep');
- $banco = new TEntry('banco');
- $conta = new TEntry('conta');
- $agencia = new TEntry('agencia');
- $operacao = new TEntry('operacao');
- $filial_id = new TDBUniqueSearch('filial_id', 'microerp', 'Filial', 'id', 'nome');
- $cargo_id = new TDBUniqueSearch('cargo_id', 'microerp', 'Cargo', 'id', 'cargo');
- $supervisor_id = new TDBUniqueSearch('supervisor_id', 'microerp', 'Supervisor', 'id', 'nome');
- $data_admissao = new TDate('data_admissao');
- $data_demissao = new TDate('data_demissao');
- $status_funcionario_id = new TDBUniqueSearch('status_funcionario_id', 'microerp', 'StatusFuncionario', 'id', 'status_funcionario');
- $anexo = new TFile('anexo');
- $observacao = new TEntry('observacao');
- // add the fields
- $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
- $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
- $this->form->addFields( [ new TLabel('Rg') ], [ $rg ] );
- $this->form->addFields( [ new TLabel('Cpf') ], [ $cpf ] );
- $this->form->addFields( [ new TLabel('Pis') ], [ $pis ] );
- $this->form->addFields( [ new TLabel('Naturalidade Id') ], [ $naturalidade_id ] );
- $this->form->addFields( [ new TLabel('Sexo Id') ], [ $sexo_id ] );
- $this->form->addFields( [ new TLabel('Data Nascimento') ], [ $data_nascimento ] );
- $this->form->addFields( [ new TLabel('Telefone') ], [ $telefone ] );
- $this->form->addFields( [ new TLabel('Celular') ], [ $celular ] );
- $this->form->addFields( [ new TLabel('Uf Id') ], [ $uf_id ] );
- $this->form->addFields( [ new TLabel('Cidade Id') ], [ $cidade_id ] );
- $this->form->addFields( [ new TLabel('Bairro Id') ], [ $bairro_id ] );
- $this->form->addFields( [ new TLabel('Logradouro') ], [ $logradouro ] );
- $this->form->addFields( [ new TLabel('Numero') ], [ $numero ] );
- $this->form->addFields( [ new TLabel('Complemento') ], [ $complemento ] );
- $this->form->addFields( [ new TLabel('Cep Id') ], [ $cep_id ] );
- $this->form->addFields( [ new TLabel('Banco') ], [ $banco ] );
- $this->form->addFields( [ new TLabel('Conta') ], [ $conta ] );
- $this->form->addFields( [ new TLabel('Agencia') ], [ $agencia ] );
- $this->form->addFields( [ new TLabel('Operacao') ], [ $operacao ] );
- $this->form->addFields( [ new TLabel('Filial Id') ], [ $filial_id ] );
- $this->form->addFields( [ new TLabel('Cargo Id') ], [ $cargo_id ] );
- $this->form->addFields( [ new TLabel('Supervisor Id') ], [ $supervisor_id ] );
- $this->form->addFields( [ new TLabel('Data Admissao') ], [ $data_admissao ] );
- $this->form->addFields( [ new TLabel('Data Demissao') ], [ $data_demissao ] );
- $this->form->addFields( [ new TLabel('Status Funcionario Id') ], [ $status_funcionario_id ] );
- $this->form->addFields( [ new TLabel('Anexo') ], [ $anexo ] );
- $this->form->addFields( [ new TLabel('Observacao') ], [ $observacao ] );
- // set sizes
- $id->setSize('100%');
- $nome->setSize('100%');
- $rg->setSize('100%');
- $cpf->setSize('100%');
- $pis->setSize('100%');
- $naturalidade_id->setSize('100%');
- $sexo_id->setSize('100%');
- $data_nascimento->setSize('100%');
- $telefone->setSize('100%');
- $celular->setSize('100%');
- $uf_id->setSize('100%');
- $cidade_id->setSize('100%');
- $bairro_id->setSize('100%');
- $logradouro->setSize('100%');
- $numero->setSize('100%');
- $complemento->setSize('100%');
- $cep_id->setSize('100%');
- $banco->setSize('100%');
- $conta->setSize('100%');
- $agencia->setSize('100%');
- $operacao->setSize('100%');
- $filial_id->setSize('100%');
- $cargo_id->setSize('100%');
- $supervisor_id->setSize('100%');
- $data_admissao->setSize('100%');
- $data_demissao->setSize('100%');
- $status_funcionario_id->setSize('100%');
- $anexo->setSize('100%');
- $observacao->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:save');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 100%';
- // $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('microerp'); // 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 Funcionario; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- $this->saveFile($object, $data, 'anexo', 'files/funcionario');
- // get the generated id
- $data->id = $object->id;
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
- new TMessage('info', AdiantiCoreTranslator::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('microerp'); // open a transaction
- $object = new Funcionario($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
- }
- }
- }
- ?>
Erickson
Os tipos de dados do BD estão compatíveis com os tipos de dados que estão vindo do form?