CD
TMULTIFILE - ERRO AO SALVAR O REGISTRO. NÃO SALVA NA PASTA ESPEC
Quando uso Tfile, o programa salva o arquivo perfeitamente na pasta files/upload
Ao trocar TFile por TMultiFile, e escolho 2 arquivos, ao salvar dá erro e não cria a subpasta e não grava os arquivos selecionados(/b>
Warning: urldecode() expects parameter 1 to be string, array given in C:xampphtdocsocorrenciaslibadiantibaseAdiantiFileSaveTrait.php on
Ao trocar TFile por TMultiFile, e escolho 2 arquivos, ao salvar dá erro e não cria a subpasta e não grava os arquivos selecionados(/b>
Warning: urldecode() expects parameter 1 to be string, array given in C:xampphtdocsocorrenciaslibadiantibaseAdiantiFileSaveTrait.php on
- <?php
- /**
- * ocorrenciaForm Form
- * @author <your name here>
- */
- class ocorrenciaForm 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_ocorrencia');
- $this->form->setFormTitle('Lançamento de Ocorrências');
- // create the form fields
- $ID_OCORRENCIA = new TEntry('ID_OCORRENCIA');
- $ID_NAVIO = new TDBCombo('ID_NAVIO', 'datasiop', 'navio', 'ID_NAVIO', 'NOME');
- $ID_TURNO = new TDBCombo('ID_TURNO', 'datasiop', 'turno', 'ID_TURNO', 'DESCRICAO');
- $ID_TIPO_OCORRENCIA = new TDBCombo('ID_TIPO_OCORRENCIA', 'datasiop', 'tipo_ocorrencia', 'ID_TIPO_OCORRENCIA', 'DESCRICAO');
- $ID_CLIENTE = new TDBCombo('ID_CLIENTE', 'datasiop', 'cliente', 'ID_CLIENTE', 'NOME');
- $DESCRICAO = new TText('DESCRICAO');
- $ACAO_IMEDIATA = new TText('ACAO_IMEDIATA');
- $DATA_OCORRENCIA = new TDate('DATA_OCORRENCIA');
- $HORA_INI = new TEntry('HORA_INI');
- $HORA_FIM = new TEntry('HORA_FIM');
- $CHUVA_MM = new TEntry('CHUVA_MM');
- $ARQUIVOS_PATH = new TMultiFile('ARQUIVOS_PATH');
- // definição de mascaras
- $DATA_OCORRENCIA->setmask('dd/mm/yyyy');
- $DATA_OCORRENCIA->setdatabasemask('yyyy-mm-dd');
- /* setmask('hh:ii')
- setnumericmask(2,',','.',true)
- */
- $HORA_INI->setmask('00:00');
- $HORA_FIM->setmask('00:00');
- // adicionar itens numa Tcombo
- //$campo->addItems(['M'=>'Masculino','F'=>'Feminino']);
- $ARQUIVOS_PATH->enablefilehandling();
- $ARQUIVOS_PATH->setallowedextensions(['png','jpg','pdf','doc']);
- // add the fields
- $this->form->addFields( [ new TLabel('Id:') ], [ $ID_OCORRENCIA ] );
- $this->form->addFields( [ new TLabel('Navio:') ], [ $ID_NAVIO ] );
- $this->form->addFields( [ new TLabel('Turno:') ], [ $ID_TURNO ] );
- $this->form->addFields( [ new TLabel('Tipo Ocorrência:') ], [ $ID_TIPO_OCORRENCIA ] );
- $this->form->addFields( [ new TLabel('Cliente:') ], [ $ID_CLIENTE ] );
- $this->form->addFields( [ new TLabel('Descrição:') ], [ $DESCRICAO ] );
- $this->form->addFields( [ new TLabel('Ação Imediata:') ], [ $ACAO_IMEDIATA ] );
- $this->form->addFields( [ new TLabel('Data Ocorrência:') ], [ $DATA_OCORRENCIA ] );
- $this->form->addFields( [ new TLabel('Hora Ini:') ], [ $HORA_INI ] );
- $this->form->addFields( [ new TLabel('Hora Fim:') ], [ $HORA_FIM ] );
- $this->form->addFields( [ new TLabel('Chuva MM:') ], [ $CHUVA_MM ] );
- $this->form->addFields( [ new TLabel('Upload Evidência:') ], [ $ARQUIVOS_PATH ] );
- $ID_NAVIO->addValidation('Id Navio', new TRequiredValidator);
- $ID_TURNO->addValidation('Id Turno', new TRequiredValidator);
- $ID_TIPO_OCORRENCIA->addValidation('Id Tipo Ocorrencia', new TRequiredValidator);
- $ID_CLIENTE->addValidation('Id Cliente', new TRequiredValidator);
- $DESCRICAO->addValidation('Descricao', new TRequiredValidator);
- $DATA_OCORRENCIA->addValidation('Data Ocorrencia', new TRequiredValidator);
- $HORA_INI->addValidation('Hora Ini', new TRequiredValidator);
- // set sizes
- $ID_OCORRENCIA->setSize('10%');
- $ID_NAVIO->setSize('50%');
- $ID_TURNO->setSize('20%');
- $ID_TIPO_OCORRENCIA->setSize('50%');
- $ID_CLIENTE->setSize('50%');
- $DESCRICAO->setSize('70%');
- $ACAO_IMEDIATA->setSize('70%');
- $DATA_OCORRENCIA->setSize('20%');
- $HORA_INI->setSize('10%');
- $HORA_FIM->setSize('10%');
- $CHUVA_MM->setSize('10%');
- $ARQUIVOS_PATH->setSize('100%');
- if (!empty($ID_OCORRENCIA))
- {
- $ID_OCORRENCIA->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('datasiop'); // 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 ocorrencia; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- $this->SaveFile($object,$data,'ARQUIVOS_PATH','files/uploads');
- // get the generated ID_OCORRENCIA
- $data->ID_OCORRENCIA = $object->ID_OCORRENCIA;
- $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('datasiop'); // open a transaction
- $object = new ocorrencia($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
- }
- }
- }
Para o multifile a função é "saveFiles", no plural. E tem mais alguns parâmetros a informar:
https://adianti.com.br/framework_files/tutor/index.php?class=ProductForm&method=onEdit&id=1&key=1
Obrigado amigão. Deu certo.
Valeu !!!!