Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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; ...
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;

  1. <?php
  2. /**
  3.  * ArquivosForm Form
  4.  * @author  <your name here>
  5.  */
  6. class ArquivosForm extends TPage
  7. {
  8.     protected $form// form
  9.         
  10.     /**
  11.      * Form constructor
  12.      * @param $param Request
  13.      */
  14.     public function __construct$param )
  15.     {
  16.         parent::__construct();
  17.         
  18.         
  19.         // creates the form
  20.         $this->form = new BootstrapFormBuilder('form_Arquivos');
  21.         $this->form->setFormTitle('Arquivos');
  22.         
  23.         // create the form fields
  24.         //$idarquivos = new TEntry('idarquivos');
  25.         $arquivo = new TMultiFile('arquivo');
  26.         $idconvenio = new TEntry('idconvenio');
  27.         $datainclusao = new TDate('datainclusao');
  28.         $datalancamento = new TDate('datalancamento');
  29.         $tamanho = new TEntry('tamanho');
  30.         
  31.         
  32.               
  33.         
  34.         // add the fields
  35.         //$this->form->addFields( [ new TLabel('Idarquivos') ], [ $idarquivos ] );
  36.         //$this->form->addFields( [ new TLabel('Idconvenio') ], [ $idconvenio ] );
  37.         $this->form->addFields( [ new TLabel('Arquivo') ], [ $arquivo ] );
  38.         //$this->form->addFields( [ new TLabel('Datainclusao') ], [ $datainclusao ] );
  39.         //$this->form->addFields( [ new TLabel('Datalancamento') ], [ $datalancamento ] );
  40.         //$this->form->addFields( [ new TLabel('Tamanho') ], [ $tamanho ] );
  41.         // set sizes
  42.         //$idarquivos->setSize('100%');
  43.         //$idconvenio->setSize('100%');
  44.         $arquivo->setSize('100%');
  45.         //$datainclusao->setSize('100%');
  46.         //$datalancamento->setSize('100%');
  47.         //$tamanho->setSize('100%');
  48.         
  49.         
  50.         if (!empty($idarquivos))
  51.         {
  52.             $idarquivos->setEditable(FALSE);
  53.         }
  54.         
  55.         /** samples
  56.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  57.          $fieldX->setSize( '100%' ); // set size
  58.          **/
  59.          
  60.         // create the form actions
  61.         $btn $this->form->addAction(_t('Save'), new TAction([$this'onSave']), 'fa:save');
  62.         $btn->class 'btn btn-sm btn-primary';
  63.         $this->form->addActionLink(_t('New'),  new TAction([$this'onEdit']), 'fa:eraser red');
  64.         
  65.         // vertical box container
  66.         $container = new TVBox;
  67.         $container->style 'width: 100%';
  68.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  69.         $container->add($this->form);
  70.         
  71.         parent::add($container);
  72.     }
  73.     /**
  74.      * Save form data
  75.      * @param $param Request
  76.      */
  77.     public function onSave$param )
  78.     {
  79.         try
  80.         {
  81.             TTransaction::open('chronos'); // open a transaction
  82.             
  83.             /**
  84.             // Enable Debug logger for SQL operations inside the transaction
  85.             TTransaction::setLogger(new TLoggerSTD); // standard output
  86.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  87.             **/
  88.             
  89.             $this->form->validate(); // validate form data
  90.             $data $this->form->getData(); // get form data as array
  91.            
  92.                 
  93.                 $object = new Arquivos;  // create an empty object
  94.                 $object->fromArray( (array) $data); // load the object with data             
  95.                 $object->store(); // save the object
  96.                
  97.                     
  98.             // get the generated idarquivos
  99.             $data->idarquivos $object->idarquivos;
  100.            
  101.             $this->form->setData($data); // fill form data
  102.             TTransaction::close(); // close the transaction
  103.             
  104.             new TMessage('info'AdiantiCoreTranslator::translate('Record saved'));
  105.         }
  106.         catch (Exception $e// in case of exception
  107.         {
  108.             new TMessage('error'$e->getMessage()); // shows the exception error message
  109.             $this->form->setData$this->form->getData() ); // keep form data
  110.             TTransaction::rollback(); // undo all pending operations
  111.         }
  112.     }
  113.     
  114.     /**
  115.      * Clear form data
  116.      * @param $param Request
  117.      */
  118.     public function onClear$param )
  119.     {
  120.         $this->form->clear(TRUE);
  121.     }
  122.     
  123.     /**
  124.      * Load object to form data
  125.      * @param $param Request
  126.      */
  127.     public function onEdit$param )
  128.     {
  129.         try
  130.         {
  131.             if (isset($param['key']))
  132.             {
  133.                 $key $param['key'];  // get the parameter $key
  134.                 TTransaction::open('chronos'); // open a transaction
  135.                 $object = new Arquivos($key); // instantiates the Active Record
  136.                 $this->form->setData($object); // fill the form
  137.                 TTransaction::close(); // close the transaction
  138.             }
  139.             else
  140.             {
  141.                 $this->form->clear(TRUE);
  142.             }
  143.         }
  144.         catch (Exception $e// in case of exception
  145.         {
  146.             new TMessage('error'$e->getMessage()); // shows the exception error message
  147.             TTransaction::rollback(); // undo all pending operations
  148.         }
  149.     }
  150. }

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (6)


NR

https://adianti.com.br/framework_files/tutor/index.php?class=ProductForm&method=onEdit
FS

Este exemplo eu cheguei a ver porém ele não salva no bando de dados os nomes dos arquivos upados.
NR

A função saveFiles(chamada na onSave) faz exatamente isso:
  1. <?php
  2. // onSave
  3. $this->saveFiles($object$data'images''files/images''ProductImage''image''product_id');
  4. ?>

Se não estiver gravando corretamente, confira os parâmetros passados:
  1. <?php
  2. /**
  3.      * Save files
  4.      * @param $object      Active Record
  5.      * @param $data        Form data
  6.      * @param $input_name  Input field name
  7.      * @param $target_path Target file path
  8.      * @param $model_files Files Active Record
  9.      * @param $file_field  File field in model_files
  10.      * @param $foreign_key Foreign key to $object
  11.      */
  12.     public function saveFiles($object$data$input_name$target_path$model_files$file_field$foreign_key)
  13. ?>
FS

agora esta dando este erro:
urldecode() expects parameter 1 to be string, array given in /lib/adianti/base/AdiantiFileSaveTrait.php on line 28
FS

$this->saveFile($object, $data, 'arquivo', 'files/convenios');
Coloquei desta forma, não sei que parametro é este que esta faltando.
FS

Consegue resolver o saveFile ou seja enviando somente um arquivo, agora no saveFiles que posso enviar varios arquivos este não funciona.