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.
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.
- <?php
- /**
- * PessoaForm
- *
- * @version 1.0
- * @package dbaerp
- * @subpackage control
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class PessoaForm extends TWindow
- {
- protected $form; // form
- use Adianti\Base\AdiantiFileSaveTrait;
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- parent::setSize(0.8, null);
- parent::removePadding();
- parent::removeTitleBar();
- //parent::disableEscape();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Pessoa');
- $this->form->setFormTitle('Pessoa');
- $this->form->setProperty('style', 'margin:0;border:0');
- $this->form->setClientValidation(true);
- $this->form->appendPage('Informações Basicas');
- // create the form fields
- $id = new TEntry('id');
- $nome = new TEntry('nome');
- $nome_fantasia = new TEntry('nome_fantasia');
- $tipo = new TCombo('tipo');
- $codigo_nacional = new TEntry('codigo_nacional');
- $codigo_estadual = new TEntry('codigo_estadual');
- $codigo_municipal = new TEntry('codigo_municipal');
- $ibge = new TEntry('ibge');
- $fone = new TEntry('fone');
- $email = new TEntry('email');
- $observacao = new TText('observacao');
- $cep = new TEntry('cep');
- $logradouro = new TEntry('logradouro');
- $numero = new TEntry('numero');
- $complemento = new TEntry('complemento');
- $bairro = new TEntry('bairro');
- //------------------------------------------------
- $photo_path = new TFile('photo_path');
- $images = new TMultiFile('images');
- // allow just these extensions
- $photo_path->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
- $images->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
- // enable progress bar, preview
- $photo_path->enableFileHandling();
- $photo_path->enablePopover();
- // enable progress bar, preview, and gallery mode
- $images->enableFileHandling();
- $images->enableImageGallery();
- $images->enablePopover('Preview', '<img style="max-width:300px" src="download.php?file={file_name}">');
- //--------------------------------------------------
- $filter = new TCriteria;
- $filter->add(new TFilter('id', '<', '0'));
- $cidade_id = new TDBCombo('cidade_id', 'dbaerp', 'Cidade', 'id', 'nome', 'nome', $filter);
- $grupo_id = new TDBUniqueSearch('grupo_id', 'dbaerp', 'Grupo', 'id', 'nome');
- $papeis_id = new TDBMultiSearch('papeis_id', 'dbaerp', 'Papel', 'id', 'nome');
- $estado_id = new TDBCombo('estado_id', 'dbaerp', 'Estado', 'id', '{nome} ({uf})');
- $estado_id->setChangeAction( new TAction( [$this, 'onChangeEstado'] ) );
- $cep->setExitAction( new TAction([ $this, 'onExitCEP']) );
- $codigo_nacional->setExitAction( new TAction( [$this, 'onExitCNPJ'] ) );
- $cidade_id->enableSearch();
- $estado_id->enableSearch();
- $grupo_id->setMinLength(0);
- $papeis_id->setMinLength(0);
- $papeis_id->setSize('100%', 60);
- $observacao->setSize('100%', 60);
- $tipo->addItems( ['F' => 'Física', 'J' => 'Jurídica' ] );
- // add the fields
- $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
- $this->form->addFields( [ new TLabel('Tipo') ], [ $tipo ], [ new TLabel('CPF/CNPJ') ], [ $codigo_nacional ] );
- $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
- $this->form->addFields( [ new TLabel('Nome Fantasia') ], [ $nome_fantasia ] );
- $this->form->addFields( [ new TLabel('Classe')], [ $papeis_id ], [ new TLabel('Grupo') ], [ $grupo_id ] );
- $this->form->addFields( [ new TLabel('I.E.') ], [ $codigo_estadual ], [ new TLabel('I.M.') ], [ $codigo_municipal ] );
- $this->form->addFields( [ new TLabel('Fone') ], [ $fone ], [ new TLabel('Email') ], [ $email ] );
- $this->form->addFields( [ new TLabel('Observacao') ], [ $observacao ] );
- $this->form->addContent( [new TFormSeparator('Endereço')]);
- $this->form->addFields( [ new TLabel('Cep') ], [ $cep ] )->layout = ['col-sm-2 control-label', 'col-sm-4'];
- $this->form->addFields( [ new TLabel('Logradouro') ], [ $logradouro ], [ new TLabel('Numero') ], [ $numero ] );
- $this->form->addFields( [ new TLabel('Complemento') ], [ $complemento ],[ new TLabel('IBGE') ], [ $ibge ] ,[ new TLabel('Bairro') ], [ $bairro ] );
- $this->form->addFields( [ new TLabel('Estado') ], [$estado_id], [ new TLabel('Cidade') ], [ $cidade_id ] );
- // set sizes
- $id->setSize('100%');
- $nome->setSize('100%');
- $nome_fantasia->setSize('100%');
- $tipo->setSize('100%');
- $codigo_nacional->setSize('100%');
- $codigo_estadual->setSize('100%');
- $codigo_municipal->setSize('100%');
- $fone->setSize('100%');
- $email->setSize('100%');
- $observacao->setSize('100%');
- $cep->setSize('100%');
- $logradouro->setSize('100%');
- $numero->setSize('100%');
- $complemento->setSize('100%');
- $bairro->setSize('100%');
- $cidade_id->setSize('100%');
- $grupo_id->setSize('100%');
- $cep->setMask('99.999-999');
- $id->setEditable(FALSE);
- $nome->addValidation('Nome', new TRequiredValidator);
- $nome_fantasia->addValidation('Nome Fantasia', new TRequiredValidator);
- $tipo->addValidation('Tipo', new TRequiredValidator);
- $codigo_nacional->addValidation('CPF/CNPJ', new TRequiredValidator);
- $grupo_id->addValidation('Grupo', new TRequiredValidator);
- $fone->addValidation('Fone', new TRequiredValidator);
- $email->addValidation('Email', new TRequiredValidator);
- $email->addValidation('Email', new TEmailValidator);
- $cidade_id->addValidation('Cidade', new TRequiredValidator);
- $cep->addValidation('CEP', new TRequiredValidator);
- $logradouro->addValidation('Logradouro', new TRequiredValidator);
- $numero->addValidation('Número', new TRequiredValidator);
- // create the form actions
- // $this->form->addHeaderActionLink(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- $this->form->addActionLink(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- // $btn = $this->form->addHeaderActionLink(_t('Save'), new TAction([$this, 'onSave']), 'fa:save');
- $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:save');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addHeaderActionLink( _t('Close'), new TAction([__CLASS__, 'onClose'], ['static'=>'1']), 'fa:times red');
- $this->form->appendPage('Outras Informações');
- $this->form->addFields( [new TLabel('Foto')], [$photo_path] );
- $this->form->addFields( [new TLabel('Images')],[$images] );
- // 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
- {
- $data = $this->form->getData(); // get form data as array
- TTransaction::open('dbaerp'); // open a transaction
- // $this->form->setData($data); // fill form data
- $this->form->validate(); // validate form data
- // $data = $this->form->getData(); // get form data as array
- $object = new Pessoa; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- // copy file to target folder
- $this->saveFile($object, $data, 'photo_path', 'files/imgpessoas');
- $this->saveFiles($object, $data, 'images', 'files/imgpessoas', 'PessoaImage', 'image', 'pessoa_id');
- PessoaPapel::where('pessoa_id', '=', $object->id)->delete();
- if ($data->papeis_id)
- {
- foreach ($data->papeis_id as $papel_id)
- {
- $pp = new PessoaPapel;
- $pp->pessoa_id = $object->id;
- $pp->papel_id = $papel_id;
- $pp->store();
- }
- }
- // get the generated id
- $data->id = $object->id;
- $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'];
- TTransaction::open('dbaerp');
- $object = new Pessoa($key);
- $object->papeis_id = PessoaPapel::where('pessoa_id', '=', $object->id)->getIndexedArray('papel_id');
- //--------------------------------------------------
- //$object->images = PessoaImage::where('pessoa_id', '=', $param['key'])->getIndexedArray('image');
- $object->images = PessoaImage::where('pessoa_id', '=', $object->id)->getIndexedArray('pessoa_id');
- //--------------------------------------------------
- // $this->form->setData($object);
- // force fire events
- $data = new stdClass;
- $data->estado_id = $object->cidade->estado->id;
- $data->cidade_id = $object->cidade_id;
- TForm::sendData('form_Pessoa', $data);
- $this->form->setData($object);
- TTransaction::close();
- }
- 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
- }
- }
- }
- ?>
- <?php
- /**
- * Product Active Record
- * @author Pablo Dall'Oglio
- */
- class PessoaImage extends TRecord
- {
- const TABLENAME = 'pessoa_image';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'max'; // {max, serial}
- /**
- * Constructor method
- */
- public function __construct($id = NULL)
- {
- parent::__construct($id);
- parent::addAttribute('pessoa_id');
- parent::addAttribute('image');
- }
- }
- ?>
Adriano, era para funcionar
Tenta deixar alinha 277
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 ?
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.
Já tinha visto, está como text. Eu uso PostgreSQL, será que tem alguma a ver ?