Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TMultiFile Exibindo na tela Olá, Estou com problemas de exibir imagem na tela com TMultiFile, está sendo gravado perfeitamente no banco, as images vão para pasta correta, na hora da gravação exibido perfeitamente em tela, mas na hora da edição não aparece. A unica coisa que fiz foi alterar o nome da pasta de gravação, está sendo gravada na pasta "imgpessoas" ao invés de "images" Obs: $photo_path = new...
AR
TMultiFile Exibindo na tela  
Olá,
Estou com problemas de exibir imagem na tela com TMultiFile, está sendo gravado perfeitamente no banco, as images vão para pasta correta, na hora da gravação exibido perfeitamente em tela, mas na hora da edição não aparece.

A unica coisa que fiz foi alterar o nome da pasta de gravação, está sendo gravada na pasta "imgpessoas" ao invés de "images"

Obs: $photo_path = new TFile('photo_path'); está funcionando perfeitamente.

  1. <?php
  2. /**
  3.  * PessoaForm
  4.  *
  5.  * @version    1.0
  6.  * @package    dbaerp
  7.  * @subpackage control
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class PessoaForm extends TWindow
  13. {
  14.     protected $form// form
  15.     
  16.     use Adianti\Base\AdiantiFileSaveTrait;
  17.     
  18.     
  19.     /**
  20.      * Form constructor
  21.      * @param $param Request
  22.      */
  23.     public function __construct$param )
  24.     {
  25.         parent::__construct();
  26.         parent::setSize(0.8null);
  27.         parent::removePadding();
  28.         parent::removeTitleBar();
  29.         //parent::disableEscape();
  30.         
  31.         // creates the form
  32.         $this->form = new BootstrapFormBuilder('form_Pessoa');
  33.         $this->form->setFormTitle('Pessoa');
  34.         $this->form->setProperty('style''margin:0;border:0');
  35.         $this->form->setClientValidation(true);
  36.         $this->form->appendPage('Informações Basicas');
  37.         // create the form fields
  38.         $id = new TEntry('id');
  39.         $nome = new TEntry('nome');
  40.         $nome_fantasia = new TEntry('nome_fantasia');
  41.         $tipo = new TCombo('tipo');
  42.         $codigo_nacional = new TEntry('codigo_nacional');
  43.         $codigo_estadual = new TEntry('codigo_estadual');
  44.         $codigo_municipal = new TEntry('codigo_municipal');
  45.         $ibge = new TEntry('ibge');
  46.         $fone = new TEntry('fone');
  47.         $email = new TEntry('email');
  48.         $observacao = new TText('observacao');
  49.         $cep = new TEntry('cep');
  50.         $logradouro = new TEntry('logradouro');
  51.         $numero = new TEntry('numero');
  52.         $complemento = new TEntry('complemento');
  53.         $bairro = new TEntry('bairro');
  54.         
  55.    //------------------------------------------------
  56.         
  57.         $photo_path  = new TFile('photo_path');
  58.         $images      = new TMultiFile('images');
  59.    
  60.         // allow just these extensions
  61.         $photo_path->setAllowedExtensions( ['gif''png''jpg''jpeg'] );
  62.         $images->setAllowedExtensions( ['gif''png''jpg''jpeg'] );
  63.  
  64.         
  65.         // enable progress bar, preview
  66.         $photo_path->enableFileHandling();
  67.         $photo_path->enablePopover();
  68.  
  69.     
  70.         // enable progress bar, preview, and gallery mode
  71.         $images->enableFileHandling();
  72.         $images->enableImageGallery();
  73.         $images->enablePopover('Preview''<img style="max-width:300px" src="download.php?file={file_name}">');
  74.  //--------------------------------------------------  
  75.         
  76.         
  77.         $filter = new TCriteria;
  78.         $filter->add(new TFilter('id''<''0'));
  79.         $cidade_id = new TDBCombo('cidade_id''dbaerp''Cidade''id''nome''nome'$filter);
  80.         $grupo_id = new TDBUniqueSearch('grupo_id''dbaerp''Grupo''id''nome');
  81.         $papeis_id = new TDBMultiSearch('papeis_id''dbaerp''Papel''id''nome');
  82.         $estado_id = new TDBCombo('estado_id''dbaerp''Estado''id''{nome} ({uf})');
  83.         
  84.         $estado_id->setChangeAction( new TAction( [$this'onChangeEstado'] ) );
  85.         $cep->setExitAction( new TAction([ $this'onExitCEP']) );
  86.         $codigo_nacional->setExitAction( new TAction( [$this'onExitCNPJ'] ) );
  87.         
  88.         $cidade_id->enableSearch();
  89.         $estado_id->enableSearch();
  90.         $grupo_id->setMinLength(0);
  91.         $papeis_id->setMinLength(0);
  92.         $papeis_id->setSize('100%'60);
  93.         $observacao->setSize('100%'60);
  94.         $tipo->addItems( ['F' => 'Física''J' => 'Jurídica' ] );
  95.         
  96.         // add the fields
  97.         $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  98.         $this->form->addFields( [ new TLabel('Tipo') ], [ $tipo ], [ new TLabel('CPF/CNPJ') ], [ $codigo_nacional ] );
  99.         $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
  100.         $this->form->addFields( [ new TLabel('Nome Fantasia') ], [ $nome_fantasia ] );
  101.         $this->form->addFields( [ new TLabel('Classe')], [ $papeis_id ], [ new TLabel('Grupo') ], [ $grupo_id ] );
  102.         $this->form->addFields( [ new TLabel('I.E.') ], [ $codigo_estadual ], [ new TLabel('I.M.') ], [ $codigo_municipal ] );
  103.         $this->form->addFields( [ new TLabel('Fone') ], [ $fone ], [ new TLabel('Email') ], [ $email ] );
  104.         $this->form->addFields( [ new TLabel('Observacao') ], [ $observacao ] );
  105.         
  106.         $this->form->addContent( [new TFormSeparator('Endereço')]);
  107.         $this->form->addFields( [ new TLabel('Cep') ], [ $cep ] )->layout = ['col-sm-2 control-label''col-sm-4'];
  108.         $this->form->addFields( [ new TLabel('Logradouro') ], [ $logradouro ], [ new TLabel('Numero') ], [ $numero ] );
  109.         $this->form->addFields( [ new TLabel('Complemento') ], [ $complemento ],[ new TLabel('IBGE') ], [ $ibge ] ,[ new TLabel('Bairro') ], [ $bairro ] );
  110.         
  111.         $this->form->addFields( [ new TLabel('Estado') ], [$estado_id], [ new TLabel('Cidade') ], [ $cidade_id ] );
  112.         
  113.         // set sizes
  114.         $id->setSize('100%');
  115.         $nome->setSize('100%');
  116.         $nome_fantasia->setSize('100%');
  117.         $tipo->setSize('100%');
  118.         $codigo_nacional->setSize('100%');
  119.         $codigo_estadual->setSize('100%');
  120.         $codigo_municipal->setSize('100%');
  121.         $fone->setSize('100%');
  122.         $email->setSize('100%');
  123.         $observacao->setSize('100%');
  124.         $cep->setSize('100%');
  125.         $logradouro->setSize('100%');
  126.         $numero->setSize('100%');
  127.         $complemento->setSize('100%');
  128.         $bairro->setSize('100%');
  129.         $cidade_id->setSize('100%');
  130.         $grupo_id->setSize('100%');
  131.         $cep->setMask('99.999-999');
  132.         
  133.         
  134.         $id->setEditable(FALSE);
  135.         $nome->addValidation('Nome', new TRequiredValidator);
  136.         $nome_fantasia->addValidation('Nome Fantasia', new TRequiredValidator);
  137.         $tipo->addValidation('Tipo', new TRequiredValidator);
  138.         $codigo_nacional->addValidation('CPF/CNPJ', new TRequiredValidator);
  139.         $grupo_id->addValidation('Grupo', new TRequiredValidator);
  140.         $fone->addValidation('Fone', new TRequiredValidator);
  141.         $email->addValidation('Email', new TRequiredValidator);
  142.         $email->addValidation('Email', new TEmailValidator);
  143.         $cidade_id->addValidation('Cidade', new TRequiredValidator);
  144.         $cep->addValidation('CEP', new TRequiredValidator);
  145.         $logradouro->addValidation('Logradouro', new TRequiredValidator);
  146.         $numero->addValidation('Número', new TRequiredValidator);
  147.         
  148.         // create the form actions
  149.     
  150.        //  $this->form->addHeaderActionLink(_t('New'),  new TAction([$this, 'onEdit']), 'fa:eraser red');
  151.         $this->form->addActionLink(_t('New'),  new TAction([$this'onEdit']), 'fa:eraser red');
  152.  
  153.     
  154.         
  155.       //  $btn = $this->form->addHeaderActionLink(_t('Save'), new TAction([$this, 'onSave']), 'fa:save');
  156.        $btn $this->form->addAction(_t('Save'), new TAction([$this'onSave']), 'fa:save');
  157.        $btn->class 'btn btn-sm btn-primary';
  158.        
  159.         
  160.         $this->form->addHeaderActionLink_t('Close'),  new TAction([__CLASS__'onClose'], ['static'=>'1']), 'fa:times red');
  161.       
  162.         $this->form->appendPage('Outras Informações'); 
  163.         $this->form->addFields( [new TLabel('Foto')],  [$photo_path] );
  164.         $this->form->addFields( [new TLabel('Images')],[$images] );
  165.  
  166.         
  167.         
  168.         
  169.         // vertical box container
  170.         $container = new TVBox;
  171.         $container->style 'width: 100%';
  172.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  173.         $container->add($this->form);
  174.         
  175.         parent::add($container);
  176.     }
  177.     /**
  178.      * Save form data
  179.      * @param $param Request
  180.      */
  181.     public function onSave$param )
  182.     {
  183.         try
  184.         {
  185.         
  186.             $data $this->form->getData(); // get form data as array
  187.         
  188.             TTransaction::open('dbaerp'); // open a transaction
  189.             
  190.           //   $this->form->setData($data); // fill form data
  191.             
  192.             
  193.             $this->form->validate(); // validate form data
  194.            // $data = $this->form->getData(); // get form data as array
  195.             
  196.             $object = new Pessoa;  // create an empty object
  197.             $object->fromArray( (array) $data); // load the object with data
  198.             $object->store(); // save the object
  199.             
  200.             
  201.             // copy file to target folder
  202.             $this->saveFile($object$data'photo_path''files/imgpessoas');
  203.             $this->saveFiles($object$data'images''files/imgpessoas''PessoaImage''image''pessoa_id');
  204.                       
  205.             
  206.             
  207.             PessoaPapel::where('pessoa_id''='$object->id)->delete();
  208.             
  209.             if ($data->papeis_id)
  210.             {
  211.                 foreach ($data->papeis_id as $papel_id)
  212.                 {
  213.                     $pp = new PessoaPapel;
  214.                     $pp->pessoa_id $object->id;
  215.                     $pp->papel_id  $papel_id;
  216.                     $pp->store();
  217.                 }
  218.             }
  219.             
  220.             
  221.             
  222.             // get the generated id
  223.             $data->id $object->id;
  224.             $this->form->setData($data); // fill form data
  225.             
  226.             
  227.             TTransaction::close(); // close the transaction
  228.             
  229.             new TMessage('info'AdiantiCoreTranslator::translate('Record saved'));
  230.         }
  231.         catch (Exception $e// in case of exception
  232.         {
  233.             new TMessage('error'$e->getMessage()); // shows the exception error message
  234.             $this->form->setData$this->form->getData() ); // keep form data
  235.             TTransaction::rollback(); // undo all pending operations
  236.         }
  237.     }
  238.     
  239.     /**
  240.      * Clear form data
  241.      * @param $param Request
  242.      */
  243.     public function onClear$param )
  244.     {
  245.         $this->form->clear(TRUE);
  246.     }
  247.     
  248.     /**
  249.      * Load object to form data
  250.      * @param $param Request
  251.      */
  252.     public function onEdit$param )
  253.     {
  254.         try
  255.         {
  256.             if (isset($param['key']))
  257.             {
  258.                 $key $param['key'];
  259.                 TTransaction::open('dbaerp');
  260.                 $object = new Pessoa($key);
  261.                 
  262.                 $object->papeis_id PessoaPapel::where('pessoa_id''='$object->id)->getIndexedArray('papel_id');
  263.                 
  264.                 //--------------------------------------------------
  265.                //$object->images = PessoaImage::where('pessoa_id', '=', $param['key'])->getIndexedArray('image');
  266.                 $object->images PessoaImage::where('pessoa_id''='$object->id)->getIndexedArray('pessoa_id');
  267.  
  268.                 //--------------------------------------------------
  269.                 
  270.              //   $this->form->setData($object);
  271.                 
  272.                 // force fire events
  273.                 $data = new stdClass;
  274.                 $data->estado_id $object->cidade->estado->id;
  275.                 $data->cidade_id $object->cidade_id;
  276.                 TForm::sendData('form_Pessoa'$data);
  277.                 
  278.                 
  279.                  $this->form->setData($object);
  280.                 
  281.                 TTransaction::close();
  282.             }
  283.             else
  284.             {
  285.                 $this->form->clear(TRUE);
  286.             }
  287.         }
  288.         catch (Exception $e// in case of exception
  289.         {
  290.             new TMessage('error'$e->getMessage()); // shows the exception error message
  291.             TTransaction::rollback(); // undo all pending operations
  292.         }
  293.     }
  294.     
  295.  }
  296. ?>



  1. <?php
  2. /**
  3.  * Product Active Record
  4.  * @author  Pablo Dall'Oglio
  5.  */
  6. class PessoaImage extends TRecord
  7. {
  8.     const TABLENAME 'pessoa_image';
  9.     const PRIMARYKEY'id';
  10.     const IDPOLICY =  'max'// {max, serial}
  11.     
  12.     /**
  13.      * Constructor method
  14.      */
  15.     public function __construct($id NULL)
  16.     {
  17.         parent::__construct($id);
  18.         
  19.         parent::addAttribute('pessoa_id');
  20.         parent::addAttribute('image');
  21.     }
  22. }
  23. ?>





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


RB

Adriano, era para funcionar

Tenta deixar alinha 277
  1. <?php
  2. $object->images PessoaImage::where('pessoa_id''='$param['key'])->getIndexedArray('image');
  3. ?>
AR

Obrigado por me responder, Rubens!

Assim a imagem aparece perfeitamente, só que na gravação recebo esse erro:

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "files/imgpessoas/1/ft3.jpg"

Saberia me dizer como resolvo ?
RB

Adriano,

Prece que o tipo de dado que esta gravando esta diferente do definido na tabela ( Parece que o campo image esta definido como integer).

Verifica se o campo image da tabela pessoa_image esta como integer e mude para text ou varchar.
AR

Já tinha visto, está como text. Eu uso PostgreSQL, será que tem alguma a ver ?