Lançado Adianti Framework 7.6!
Clique aqui para saber mais
grid Listagem de registro não exibe imagem Não estou conseguindo mostrar uma imagem em um grid, alguém pode ajudar? Com o adianti studio, no menu "Nova pagina/Nova listagem de registros" gerei o formulário, porém ele não mostra a imagem correspondente que está salva na raiz do projeto na pasta " /tmp" ...
MC
grid Listagem de registro não exibe imagem  
Não estou conseguindo mostrar uma imagem em um grid, alguém pode ajudar?
Com o adianti studio, no menu "Nova pagina/Nova listagem de registros" gerei o formulário, porém ele não mostra a imagem correspondente que está salva na raiz do projeto na pasta " /tmp"
  1. <?php
  2. /**
  3.  * Imagem_marcadorList Listing
  4.  * @author  <your name here>
  5.  */
  6. class Imagem_marcadorList extends TStandardList
  7. {
  8.     protected $form;     // registration form
  9.     protected $datagrid// listing
  10.     protected $pageNavigation;
  11.     protected $formgrid;
  12.     protected $deleteButton;
  13.     protected $transformCallback;
  14.     
  15.     /**
  16.      * Page constructor
  17.      */
  18.     public function __construct()
  19.     {
  20.         parent::__construct();
  21.         
  22.         parent::setDatabase('bancopatrulharural');            // defines the database
  23.         parent::setActiveRecord('Imagem_marcador');   // defines the active record
  24.         parent::setDefaultOrder('id''asc');         // defines the default order
  25.         // parent::setCriteria($criteria) // define a standard filter
  26.         
  27.         // creates the form
  28.         $this->form = new TQuickForm('form_search_Imagem_marcador');
  29.         $this->form->class 'tform'// change CSS class
  30.         
  31.         $this->form->style 'display: table;width:100%'// change style
  32.         $this->form->setFormTitle('Imagem_marcador');
  33.         
  34.         
  35.         // keep the form filled during navigation with session data
  36.        // $this->form->setData( TSession::getValue('Imagem_marcador_filter_data') );
  37.         
  38.         // add the search form actions
  39.         $this->form->addQuickAction(_t('Find'), new TAction(array($this'onSearch')), 'fa:search');
  40.         $this->form->addQuickAction(_t('New'),  new TAction(array('Imagem_marcadorForm''onEdit')), 'bs:plus-sign green');
  41.         
  42.         // creates a DataGrid
  43.         $this->datagrid = new TDataGrid;
  44.         
  45.         $this->datagrid->style 'width: 100%';
  46.         $this->datagrid->datatable 'true';
  47.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  48.         
  49.         // creates the datagrid columns
  50.         $column_id = new TDataGridColumn('id''Id''right');
  51.         $column_nome = new TDataGridColumn('nome''Nome''left');
  52.         $column_imagem = new TDataGridColumn('imagem''Imagem''left'160);
  53.         //$column_imagem->setTransformer( array($this, 'showImage') ); 
  54.         // add the columns to the DataGrid
  55.         $this->datagrid->addColumn($column_id);
  56.         $this->datagrid->addColumn($column_nome);
  57.         $this->datagrid->addColumn($column_imagem);
  58.         // define the transformer method over image
  59.         $column_imagem->setTransformer( function($value$object$row) {
  60.             if (file_exists($value)) {
  61.                 return new TImage($value);
  62.             }
  63.         });
  64.         
  65.         // create EDIT action
  66.         $action_edit = new TDataGridAction(array('Imagem_marcadorForm''onEdit'));
  67.         $action_edit->setUseButton(TRUE);
  68.         $action_edit->setButtonClass('btn btn-default');
  69.         $action_edit->setLabel(_t('Edit'));
  70.         $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  71.         $action_edit->setField('id');
  72.         $this->datagrid->addAction($action_edit);
  73.         
  74.         // create DELETE action
  75.         $action_del = new TDataGridAction(array($this'onDelete'));
  76.         $action_del->setUseButton(TRUE);
  77.         $action_del->setButtonClass('btn btn-default');
  78.         $action_del->setLabel(_t('Delete'));
  79.         $action_del->setImage('fa:trash-o red fa-lg');
  80.         $action_del->setField('id');
  81.         $this->datagrid->addAction($action_del);
  82.         
  83.         // create the datagrid model
  84.         $this->datagrid->createModel();
  85.         
  86.         // create the page navigation
  87.         $this->pageNavigation = new TPageNavigation;
  88.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  89.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  90.         
  91.         // vertical box container
  92.         $container = new TVBox;
  93.         $container->style 'width: 90%';
  94.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  95.         $container->add($this->form);
  96.         $container->add($this->datagrid);
  97.         $container->add($this->pageNavigation);
  98.         
  99.         parent::add($container);
  100.     }
  101.     
  102. }
  103. </code>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (2)


NR

Qual é o caminho do arquivo que está salvo no banco de dados?

Obs: cuidado com a "/". Chamando "/tmp" você não está acessando a pasta tmp da raiz do seu projeto e sim passando o caminho absoluto da pasta "/tmp" do sistema.
MC

Resolvido!
"Qual é o caminho do arquivo que está salvo no banco de dados? " -> o proprio frame no campo TFile salva automaticamente todos os arquivos na pasta tmp por "defautl", mesmo antes de salvar o registro, então após ver alguns exemplos no fórum, adaptei "meio gambiarra", e está funcionando.


  1. <?php
  2. /**
  3.  * Imagem_marcadorForm Form
  4.  * @author  <your name here>
  5.  */
  6. class Imagem_marcadorForm 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.         // creates the form
  19.         $this->form = new TQuickForm('form_Imagem_marcador');
  20.         $this->form->class 'tform'// change CSS class
  21.         $this->form = new BootstrapFormWrapper($this->form);
  22.         $this->form->style 'display: table;width:100%'// change style
  23.         
  24.         // define the form title
  25.         $this->form->setFormTitle('Imagem_marcador');
  26.         
  27.         // create the form fields
  28.         $id = new TEntry('id');
  29.         $nome = new TEntry('nome');
  30.         $imagem = new TFile('imagem');
  31.         // add the fields
  32.         $this->form->addQuickField('Id'$id,  100 );
  33.         $this->form->addQuickField('Nome'$nome,  200 , new TRequiredValidator);
  34.         $this->form->addQuickField('Imagem'$imagem,  200 , new TRequiredValidator);
  35.         if (!empty($id))
  36.         {
  37.             $id->setEditable(FALSE);
  38.         }
  39.         
  40.         /** samples
  41.          $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  42.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  43.          $fieldX->setSize( 100, 40 ); // set size
  44.          **/
  45.          
  46.         // create the form actions
  47.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'fa:floppy-o');
  48.         $this->form->addQuickAction(_t('New'),  new TAction(array($this'onClear')), 'bs:plus-sign green');
  49.         
  50.         // vertical box container
  51.         $container = new TVBox;
  52.         $container->style 'width: 90%';
  53.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  54.         $container->add(TPanelGroup::pack('Title'$this->form));
  55.         
  56.         parent::add($container);
  57.     }
  58.     /**
  59.      * Save form data
  60.      * @param $param Request
  61.      */
  62.     public function onSave$param )
  63.     {
  64.         try
  65.         {
  66.             TTransaction::open('bancopatrulharural'); // open a transaction
  67.             
  68.             /**
  69.             // Enable Debug logger for SQL operations inside the transaction
  70.             TTransaction::setLogger(new TLoggerSTD); // standard output
  71.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  72.             **/
  73.             
  74.             $this->form->validate(); // validate form data
  75.             
  76.             $object = new Imagem_marcador;  // create an empty object
  77.             $data $this->form->getData(); // get form data as array
  78.             
  79.             $object->fromArray( (array) $data); // load the object with data
  80.            
  81.             var_dump($object);            
  82.              
  83.            // adaptado por fabiano dos santos no forúm https://www.adianti.com.br/forum/pt/view_599?exemplo-de-upload-e-download-de-arquivos
  84.            if ($object-> imagem)
  85.            {
  86.                $target_folder 'tmp/' $object-> id;
  87.                $target_file   $target_folder '/' .$object-> imagem;
  88.                @mkdir($target_folder);
  89.                rename('tmp/'.$object-> imagem$target_file);           }
  90.            
  91.            
  92.             $object->imagem "tmp/".$object->id."/".$object->imagem;  // aqui adicionei novo valor a variavel a fim de salvar corretamente o caminho no banco de dados 
  93.             
  94.            
  95.             //object->imagem = "tmp/".$object->imagem;
  96.             $object->store(); // save the object  
  97.            
  98.             
  99.             // get the generated id
  100.             $data->id $object->id;
  101.             
  102.             $this->form->setData($data); // fill form data
  103.             TTransaction::close(); // close the transaction
  104.             
  105.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  106.         }
  107.         catch (Exception $e// in case of exception
  108.         {
  109.             new TMessage('error'$e->getMessage()); // shows the exception error message
  110.             $this->form->setData$this->form->getData() ); // keep form data
  111.             TTransaction::rollback(); // undo all pending operations
  112.         }
  113.     }
  114.     
  115.     /**
  116.      * Clear form data
  117.      * @param $param Request
  118.      */
  119.     public function onClear$param )
  120.     {
  121.         $this->form->clear(TRUE);
  122.     }
  123.     
  124.     /**
  125.      * Load object to form data
  126.      * @param $param Request
  127.      */
  128.     public function onEdit$param )
  129.     {
  130.         try
  131.         {
  132.             if (isset($param['key']))
  133.             {
  134.                 $key $param['key'];  // get the parameter $key
  135.                 TTransaction::open('bancopatrulharural'); // open a transaction
  136.                 $object = new Imagem_marcador($key); // instantiates the Active Record
  137.                 $this->form->setData($object); // fill the form
  138.                 TTransaction::close(); // close the transaction
  139.             }
  140.             else
  141.             {
  142.                 $this->form->clear(TRUE);
  143.             }
  144.         }
  145.         catch (Exception $e// in case of exception
  146.         {
  147.             new TMessage('error'$e->getMessage()); // shows the exception error message
  148.             TTransaction::rollback(); // undo all pending operations
  149.         }
  150.     }
  151. }
  152. </code>


Obrigado.</your>