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: ...
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:
  1. <?php
  2. /**
  3.  * FuncionarioForm Form
  4.  * @author  <your name here>
  5.  */
  6. class FuncionarioForm extends TPage
  7. {
  8.     protected $form// form
  9.     
  10.     use Adianti\Base\AdiantiFileSaveTrait;
  11.     
  12.     /**
  13.      * Form constructor
  14.      * @param $param Request
  15.      */
  16.     public function __construct$param )
  17.     {
  18.         parent::__construct();
  19.         
  20.         
  21.         // creates the form
  22.         $this->form = new BootstrapFormBuilder('form_Funcionario');
  23.         $this->form->setFormTitle('Funcionario');
  24.         
  25.         // create the form fields
  26.         $id = new TEntry('id');
  27.         $nome = new TEntry('nome');
  28.         $rg = new TEntry('rg');
  29.         $cpf = new TEntry('cpf');
  30.         $pis = new TEntry('pis');
  31.         $naturalidade_id = new TDBUniqueSearch('naturalidade_id''microerp''Naturalidade''id''naturalidade');
  32.         $sexo_id = new TDBUniqueSearch('sexo_id''microerp''Sexo''id''sexo');
  33.         $data_nascimento = new TDate('data_nascimento');
  34.         $telefone = new TEntry('telefone');
  35.         $celular = new TEntry('celular');
  36.         $uf_id = new TDBUniqueSearch('uf_id''microerp''Uf''id''uf');
  37.         $cidade_id = new TDBUniqueSearch('cidade_id''microerp''Cidade''id''nome');
  38.         $bairro_id = new TDBUniqueSearch('bairro_id''microerp''Bairro''id''bairro');
  39.         $logradouro = new TDBUniqueSearch('logradouro''microerp''Logradouro''id''logradouro');
  40.         $numero = new TEntry('numero');
  41.         $complemento = new TEntry('complemento');
  42.         $cep_id = new TDBUniqueSearch('cep_id''microerp''Cep''id''cep');
  43.         $banco = new TEntry('banco');
  44.         $conta = new TEntry('conta');
  45.         $agencia = new TEntry('agencia');
  46.         $operacao = new TEntry('operacao');
  47.         $filial_id = new TDBUniqueSearch('filial_id''microerp''Filial''id''nome');
  48.         $cargo_id = new TDBUniqueSearch('cargo_id''microerp''Cargo''id''cargo');
  49.         $supervisor_id = new TDBUniqueSearch('supervisor_id''microerp''Supervisor''id''nome');
  50.         $data_admissao = new TDate('data_admissao');
  51.         $data_demissao = new TDate('data_demissao');
  52.         $status_funcionario_id = new TDBUniqueSearch('status_funcionario_id''microerp''StatusFuncionario''id''status_funcionario');
  53.         $anexo = new TFile('anexo');
  54.         $observacao = new TEntry('observacao');
  55.         // add the fields
  56.         $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  57.         $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
  58.         $this->form->addFields( [ new TLabel('Rg') ], [ $rg ] );
  59.         $this->form->addFields( [ new TLabel('Cpf') ], [ $cpf ] );
  60.         $this->form->addFields( [ new TLabel('Pis') ], [ $pis ] );
  61.         $this->form->addFields( [ new TLabel('Naturalidade Id') ], [ $naturalidade_id ] );
  62.         $this->form->addFields( [ new TLabel('Sexo Id') ], [ $sexo_id ] );
  63.         $this->form->addFields( [ new TLabel('Data Nascimento') ], [ $data_nascimento ] );
  64.         $this->form->addFields( [ new TLabel('Telefone') ], [ $telefone ] );
  65.         $this->form->addFields( [ new TLabel('Celular') ], [ $celular ] );
  66.         $this->form->addFields( [ new TLabel('Uf Id') ], [ $uf_id ] );
  67.         $this->form->addFields( [ new TLabel('Cidade Id') ], [ $cidade_id ] );
  68.         $this->form->addFields( [ new TLabel('Bairro Id') ], [ $bairro_id ] );
  69.         $this->form->addFields( [ new TLabel('Logradouro') ], [ $logradouro ] );
  70.         $this->form->addFields( [ new TLabel('Numero') ], [ $numero ] );
  71.         $this->form->addFields( [ new TLabel('Complemento') ], [ $complemento ] );
  72.         $this->form->addFields( [ new TLabel('Cep Id') ], [ $cep_id ] );
  73.         $this->form->addFields( [ new TLabel('Banco') ], [ $banco ] );
  74.         $this->form->addFields( [ new TLabel('Conta') ], [ $conta ] );
  75.         $this->form->addFields( [ new TLabel('Agencia') ], [ $agencia ] );
  76.         $this->form->addFields( [ new TLabel('Operacao') ], [ $operacao ] );
  77.         $this->form->addFields( [ new TLabel('Filial Id') ], [ $filial_id ] );
  78.         $this->form->addFields( [ new TLabel('Cargo Id') ], [ $cargo_id ] );
  79.         $this->form->addFields( [ new TLabel('Supervisor Id') ], [ $supervisor_id ] );
  80.         $this->form->addFields( [ new TLabel('Data Admissao') ], [ $data_admissao ] );
  81.         $this->form->addFields( [ new TLabel('Data Demissao') ], [ $data_demissao ] );
  82.         $this->form->addFields( [ new TLabel('Status Funcionario Id') ], [ $status_funcionario_id ] );
  83.         $this->form->addFields( [ new TLabel('Anexo') ], [ $anexo ] );
  84.         $this->form->addFields( [ new TLabel('Observacao') ], [ $observacao ] );
  85.         // set sizes
  86.         $id->setSize('100%');
  87.         $nome->setSize('100%');
  88.         $rg->setSize('100%');
  89.         $cpf->setSize('100%');
  90.         $pis->setSize('100%');
  91.         $naturalidade_id->setSize('100%');
  92.         $sexo_id->setSize('100%');
  93.         $data_nascimento->setSize('100%');
  94.         $telefone->setSize('100%');
  95.         $celular->setSize('100%');
  96.         $uf_id->setSize('100%');
  97.         $cidade_id->setSize('100%');
  98.         $bairro_id->setSize('100%');
  99.         $logradouro->setSize('100%');
  100.         $numero->setSize('100%');
  101.         $complemento->setSize('100%');
  102.         $cep_id->setSize('100%');
  103.         $banco->setSize('100%');
  104.         $conta->setSize('100%');
  105.         $agencia->setSize('100%');
  106.         $operacao->setSize('100%');
  107.         $filial_id->setSize('100%');
  108.         $cargo_id->setSize('100%');
  109.         $supervisor_id->setSize('100%');
  110.         $data_admissao->setSize('100%');
  111.         $data_demissao->setSize('100%');
  112.         $status_funcionario_id->setSize('100%');
  113.         $anexo->setSize('100%');
  114.         $observacao->setSize('100%');
  115.         if (!empty($id))
  116.         {
  117.             $id->setEditable(FALSE);
  118.         }
  119.         
  120.         /** samples
  121.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  122.          $fieldX->setSize( '100%' ); // set size
  123.          **/
  124.          
  125.         // create the form actions
  126.         $btn $this->form->addAction(_t('Save'), new TAction([$this'onSave']), 'fa:save');
  127.         $btn->class 'btn btn-sm btn-primary';
  128.         $this->form->addActionLink(_t('New'),  new TAction([$this'onEdit']), 'fa:eraser red');
  129.         
  130.         // vertical box container
  131.         $container = new TVBox;
  132.         $container->style 'width: 100%';
  133.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  134.         $container->add($this->form);
  135.         
  136.         parent::add($container);
  137.     }
  138.     /**
  139.      * Save form data
  140.      * @param $param Request
  141.      */
  142.     public function onSave$param )
  143.     {
  144.         try
  145.         {
  146.             TTransaction::open('microerp'); // open a transaction
  147.             
  148.             /**
  149.             // Enable Debug logger for SQL operations inside the transaction
  150.             TTransaction::setLogger(new TLoggerSTD); // standard output
  151.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  152.             **/
  153.             
  154.             $this->form->validate(); // validate form data
  155.             $data $this->form->getData(); // get form data as array
  156.             
  157.             $object = new Funcionario;  // create an empty object
  158.             $object->fromArray( (array) $data); // load the object with data
  159.             $object->store(); // save the object
  160.             
  161.             $this->saveFile($object$data'anexo''files/funcionario');
  162.             
  163.             // get the generated id
  164.             $data->id $object->id;
  165.             
  166.             $this->form->setData($data); // fill form data
  167.             TTransaction::close(); // close the transaction
  168.             
  169.             new TMessage('info'AdiantiCoreTranslator::translate('Record saved'));
  170.         }
  171.         catch (Exception $e// in case of exception
  172.         {
  173.             new TMessage('error'$e->getMessage()); // shows the exception error message
  174.             $this->form->setData$this->form->getData() ); // keep form data
  175.             TTransaction::rollback(); // undo all pending operations
  176.         }
  177.     }
  178.     
  179.     /**
  180.      * Clear form data
  181.      * @param $param Request
  182.      */
  183.     public function onClear$param )
  184.     {
  185.         $this->form->clear(TRUE);
  186.     }
  187.     
  188.     /**
  189.      * Load object to form data
  190.      * @param $param Request
  191.      */
  192.     public function onEdit$param )
  193.     {
  194.         try
  195.         {
  196.             if (isset($param['key']))
  197.             {
  198.                 $key $param['key'];  // get the parameter $key
  199.                 TTransaction::open('microerp'); // open a transaction
  200.                 $object = new Funcionario($key); // instantiates the Active Record
  201.                 $this->form->setData($object); // fill the form
  202.                 TTransaction::close(); // close the transaction
  203.             }
  204.             else
  205.             {
  206.                 $this->form->clear(TRUE);
  207.             }
  208.         }
  209.         catch (Exception $e// in case of exception
  210.         {
  211.             new TMessage('error'$e->getMessage()); // shows the exception error message
  212.             TTransaction::rollback(); // undo all pending operations
  213.         }
  214.     }
  215. }
  216. ?>

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 (1)


MG

Erickson
Os tipos de dados do BD estão compatíveis com os tipos de dados que estão vindo do form?