FS
TMultiFile
Pessoal, estou querendo salvar o meu banco de dados os arquivos puxado pelo TMultiFile, porém não estou conseguindo,
algué já passou por isso e como resolver?
segue meu código feito pelo Adianti Studio;
algué já passou por isso e como resolver?
segue meu código feito pelo Adianti Studio;
- <?php
- /**
- * ArquivosForm Form
- * @author <your name here>
- */
- class ArquivosForm extends TPage
- {
- protected $form; // form
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Arquivos');
- $this->form->setFormTitle('Arquivos');
- // create the form fields
- //$idarquivos = new TEntry('idarquivos');
- $arquivo = new TMultiFile('arquivo');
- $idconvenio = new TEntry('idconvenio');
- $datainclusao = new TDate('datainclusao');
- $datalancamento = new TDate('datalancamento');
- $tamanho = new TEntry('tamanho');
- // add the fields
- //$this->form->addFields( [ new TLabel('Idarquivos') ], [ $idarquivos ] );
- //$this->form->addFields( [ new TLabel('Idconvenio') ], [ $idconvenio ] );
- $this->form->addFields( [ new TLabel('Arquivo') ], [ $arquivo ] );
- //$this->form->addFields( [ new TLabel('Datainclusao') ], [ $datainclusao ] );
- //$this->form->addFields( [ new TLabel('Datalancamento') ], [ $datalancamento ] );
- //$this->form->addFields( [ new TLabel('Tamanho') ], [ $tamanho ] );
- // set sizes
- //$idarquivos->setSize('100%');
- //$idconvenio->setSize('100%');
- $arquivo->setSize('100%');
- //$datainclusao->setSize('100%');
- //$datalancamento->setSize('100%');
- //$tamanho->setSize('100%');
- if (!empty($idarquivos))
- {
- $idarquivos->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('chronos'); // 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 Arquivos; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- // get the generated idarquivos
- $data->idarquivos = $object->idarquivos;
- $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('chronos'); // open a transaction
- $object = new Arquivos($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
- }
- }
- }
https://adianti.com.br/framework_files/tutor/index.php?class=ProductForm&method=onEdit
Este exemplo eu cheguei a ver porém ele não salva no bando de dados os nomes dos arquivos upados.
A função saveFiles(chamada na onSave) faz exatamente isso:
Se não estiver gravando corretamente, confira os parâmetros passados:
agora esta dando este erro:
urldecode() expects parameter 1 to be string, array given in /lib/adianti/base/AdiantiFileSaveTrait.php on line 28
$this->saveFile($object, $data, 'arquivo', 'files/convenios');
Coloquei desta forma, não sei que parametro é este que esta faltando.
Consegue resolver o saveFile ou seja enviando somente um arquivo, agora no saveFiles que posso enviar varios arquivos este não funciona.