Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Exibir Imgem no Grid Pessoal, criei no Adianti Studio um cadastro de categorias e neste tem a opção de incluir uma imagem. O Upload é feito normal, onde constatei a existência da imagem na pasta tmp do meu servidor e na tabela gravado o nome do arquivo como segue (van_sat203x54.png). Mas não está aparecendo a imagem no gri da listagem. Alguém ajuda por gentileza. Segue abaixo o código da Listagem de Categori...
PS
Exibir Imgem no Grid  
Pessoal, criei no Adianti Studio um cadastro de categorias e neste tem a opção de incluir uma imagem. O Upload é feito normal, onde constatei a existência da imagem na pasta tmp do meu servidor e na tabela gravado o nome do arquivo como segue (van_sat203x54.png). Mas não está aparecendo a imagem no gri da listagem. Alguém ajuda por gentileza.
Segue abaixo o código da Listagem de Categorias:

  1. <?php
  2. /**
  3.  * PedCategoriasLista Listing
  4.  * @author  <your name here>
  5.  */
  6. class PedCategoriasLista extends TPage
  7. {
  8.     private $form// form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $formgrid;
  12.     private $loaded;
  13.     private $deleteButton;
  14.     
  15.     /**
  16.      * Class constructor
  17.      * Creates the page, the form and the listing
  18.      */
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.         
  23.         // creates the form
  24.         $this->form = new BootstrapFormBuilder('form_PedCategorias');
  25.         $this->form->setFormTitle('PedCategorias');
  26.         
  27.         // create the form fields
  28.         $id = new TEntry('id');
  29.         $ds_categoria = new TEntry('ds_categoria');
  30.         // add the fields
  31.         $this->form->addFields( [ new TLabel('Código') ], [ $id ] );
  32.         $this->form->addFields( [ new TLabel('Categoria') ], [ $ds_categoria ] );
  33.         // set sizes
  34.         $id->setSize('100%');
  35.         $ds_categoria->setSize('100%');
  36.         
  37.         // keep the form filled during navigation with session data
  38.         $this->form->setDataTSession::getValue('PedCategorias_filter_data') );
  39.         
  40.         // add the search form actions
  41.         $btn $this->form->addAction(_t('Find'), new TAction([$this'onSearch']), 'fa:search');
  42.         $btn->class 'btn btn-sm btn-primary';
  43.         $this->form->addActionLink(_t('New'), new TAction(['PedCategoriasForm''onEdit']), 'fa:plus green');
  44.         
  45.         // creates a Datagrid
  46.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  47.         $this->datagrid->style 'width: 100%';
  48.         $this->datagrid->datatable 'true';
  49.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  50.         
  51.         // creates the datagrid columns
  52.         $column_id = new TDataGridColumn('id''Código''right'30);
  53.         $column_ds_categoria = new TDataGridColumn('ds_categoria''Categoria''left');
  54.         $column_img_catego = new TDataGridColumn('img_catego''Imagem''center');
  55.         // add the columns to the DataGrid
  56.         $this->datagrid->addColumn($column_id);
  57.         $this->datagrid->addColumn($column_ds_categoria);
  58.         $this->datagrid->addColumn($column_img_catego);
  59.         // creates the datagrid column actions
  60.         $column_id->setAction(new TAction([$this'onReload']), ['order' => 'id']);
  61.         $column_ds_categoria->setAction(new TAction([$this'onReload']), ['order' => 'ds_categoria']);
  62.         // define the transformer method over image
  63.         $column_ds_categoria->setTransformer( function($value$object$row) {
  64.             return strtoupper($value);
  65.         });
  66.         // define the transformer method over image
  67.         $column_img_catego->setTransformer( function($value$object$row) {
  68.             if (file_exists($value)) {
  69.                 return new TImage($value);
  70.             }
  71.         });
  72.         
  73.         // create EDIT action
  74.         $action_edit = new TDataGridAction(['PedCategoriasForm''onEdit']);
  75.         //$action_edit->setUseButton(TRUE);
  76.         //$action_edit->setButtonClass('btn btn-default');
  77.         $action_edit->setLabel(_t('Edit'));
  78.         $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  79.         $action_edit->setField('id');
  80.         $this->datagrid->addAction($action_edit);
  81.         
  82.         // create DELETE action
  83.         $action_del = new TDataGridAction(array($this'onDelete'));
  84.         //$action_del->setUseButton(TRUE);
  85.         //$action_del->setButtonClass('btn btn-default');
  86.         $action_del->setLabel(_t('Delete'));
  87.         $action_del->setImage('fa:trash-o red fa-lg');
  88.         $action_del->setField('id');
  89.         $this->datagrid->addAction($action_del);
  90.         
  91.         // create the datagrid model
  92.         $this->datagrid->createModel();
  93.         
  94.         // creates the page navigation
  95.         $this->pageNavigation = new TPageNavigation;
  96.         $this->pageNavigation->setAction(new TAction([$this'onReload']));
  97.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  98.         
  99.         // vertical box container
  100.         $container = new TVBox;
  101.         $container->style 'width: 90%';
  102.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  103.         $container->add($this->form);
  104.         $container->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation));
  105.         
  106.         parent::add($container);
  107.     }
  108.     
  109.     /**
  110.      * Inline record editing
  111.      * @param $param Array containing:
  112.      *              key: object ID value
  113.      *              field name: object attribute to be updated
  114.      *              value: new attribute content 
  115.      */
  116.     public function onInlineEdit($param)
  117.     {
  118.         try
  119.         {
  120.             // get the parameter $key
  121.             $field $param['field'];
  122.             $key   $param['key'];
  123.             $value $param['value'];
  124.             
  125.             TTransaction::open('sispedidos'); // open a transaction with database
  126.             $object = new PedCategorias($key); // instantiates the Active Record
  127.             $object->{$field} = $value;
  128.             $object->store(); // update the object in the database
  129.             TTransaction::close(); // close the transaction
  130.             
  131.             $this->onReload($param); // reload the listing
  132.             new TMessage('info'"Record Updated");
  133.         }
  134.         catch (Exception $e// in case of exception
  135.         {
  136.             new TMessage('error'$e->getMessage()); // shows the exception error message
  137.             TTransaction::rollback(); // undo all pending operations
  138.         }
  139.     }
  140.     
  141.     /**
  142.      * Register the filter in the session
  143.      */
  144.     public function onSearch()
  145.     {
  146.         // get the search form data
  147.         $data $this->form->getData();
  148.         
  149.         // clear session filters
  150.         TSession::setValue('PedCategoriasLista_filter_id',   NULL);
  151.         TSession::setValue('PedCategoriasLista_filter_ds_categoria',   NULL);
  152.         if (isset($data->id) AND ($data->id)) {
  153.             $filter = new TFilter('id''='"$data->id"); // create the filter
  154.             TSession::setValue('PedCategoriasLista_filter_id',   $filter); // stores the filter in the session
  155.         }
  156.         if (isset($data->ds_categoria) AND ($data->ds_categoria)) {
  157.             $filter = new TFilter('ds_categoria''like'"%{$data->ds_categoria}%"); // create the filter
  158.             TSession::setValue('PedCategoriasLista_filter_ds_categoria',   $filter); // stores the filter in the session
  159.         }
  160.         
  161.         // fill the form with data again
  162.         $this->form->setData($data);
  163.         
  164.         // keep the search data in the session
  165.         TSession::setValue('PedCategorias_filter_data'$data);
  166.         
  167.         $param = array();
  168.         $param['offset']    =0;
  169.         $param['first_page']=1;
  170.         $this->onReload($param);
  171.     }
  172.     
  173.     /**
  174.      * Load the datagrid with data
  175.      */
  176.     public function onReload($param NULL)
  177.     {
  178.         try
  179.         {
  180.             // open a transaction with database 'sispedidos'
  181.             TTransaction::open('sispedidos');
  182.             
  183.             // creates a repository for PedCategorias
  184.             $repository = new TRepository('PedCategorias');
  185.             $limit 10;
  186.             // creates a criteria
  187.             $criteria = new TCriteria;
  188.             
  189.             // default order
  190.             if (empty($param['order']))
  191.             {
  192.                 $param['order'] = 'id';
  193.                 $param['direction'] = 'asc';
  194.             }
  195.             $criteria->setProperties($param); // order, offset
  196.             $criteria->setProperty('limit'$limit);
  197.             
  198.             if (TSession::getValue('PedCategoriasLista_filter_id')) {
  199.                 $criteria->add(TSession::getValue('PedCategoriasLista_filter_id')); // add the session filter
  200.             }
  201.             if (TSession::getValue('PedCategoriasLista_filter_ds_categoria')) {
  202.                 $criteria->add(TSession::getValue('PedCategoriasLista_filter_ds_categoria')); // add the session filter
  203.             }
  204.             
  205.             // load the objects according to criteria
  206.             $objects $repository->load($criteriaFALSE);
  207.             
  208.             if (is_callable($this->transformCallback))
  209.             {
  210.                 call_user_func($this->transformCallback$objects$param);
  211.             }
  212.             
  213.             $this->datagrid->clear();
  214.             if ($objects)
  215.             {
  216.                 // iterate the collection of active records
  217.                 foreach ($objects as $object)
  218.                 {
  219.                     // add the object inside the datagrid
  220.                     $this->datagrid->addItem($object);
  221.                 }
  222.             }
  223.             
  224.             // reset the criteria for record count
  225.             $criteria->resetProperties();
  226.             $count$repository->count($criteria);
  227.             
  228.             $this->pageNavigation->setCount($count); // count of records
  229.             $this->pageNavigation->setProperties($param); // order, page
  230.             $this->pageNavigation->setLimit($limit); // limit
  231.             
  232.             // close the transaction
  233.             TTransaction::close();
  234.             $this->loaded true;
  235.         }
  236.         catch (Exception $e// in case of exception
  237.         {
  238.             // shows the exception error message
  239.             new TMessage('error'$e->getMessage());
  240.             // undo all pending operations
  241.             TTransaction::rollback();
  242.         }
  243.     }
  244.     
  245.     /**
  246.      * Ask before deletion
  247.      */
  248.     public static function onDelete($param)
  249.     {
  250.         // define the delete action
  251.         $action = new TAction([__CLASS__'Delete']);
  252.         $action->setParameters($param); // pass the key parameter ahead
  253.         
  254.         // shows a dialog to the user
  255.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  256.     }
  257.     
  258.     /**
  259.      * Delete a record
  260.      */
  261.     public static function Delete($param)
  262.     {
  263.         try
  264.         {
  265.             $key=$param['key']; // get the parameter $key
  266.             TTransaction::open('sispedidos'); // open a transaction with database
  267.             $object = new PedCategorias($keyFALSE); // instantiates the Active Record
  268.             $object->delete(); // deletes the object from the database
  269.             TTransaction::close(); // close the transaction
  270.             
  271.             $pos_action = new TAction([__CLASS__'onReload']);
  272.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  273.         }
  274.         catch (Exception $e// in case of exception
  275.         {
  276.             new TMessage('error'$e->getMessage()); // shows the exception error message
  277.             TTransaction::rollback(); // undo all pending operations
  278.         }
  279.     }    
  280.     
  281.     /**
  282.      * method show()
  283.      * Shows the page
  284.      */
  285.     public function show()
  286.     {
  287.         // check if the datagrid is already loaded
  288.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload''onSearch')))) )
  289.         {
  290.             if (func_num_args() > 0)
  291.             {
  292.                 $this->onReloadfunc_get_arg(0) );
  293.             }
  294.             else
  295.             {
  296.                 $this->onReload();
  297.             }
  298.         }
  299.         parent::show();
  300.     }
  301.     
  302. }

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


LA

Paulo, altera esta linha:

  1. <?php
  2. //Esta
  3. // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  4. //Para
  5. $this->datagrid->enablePopover('Foto principal''<img src="{photo_path}" width="350" height="250">');
  6. ?>
PS

Luis, fiz a alteração porém continua sem mostrar
PS

Alguém mais pode dar uma ajuda?
Precisando com urgência...
PS

Só lembrando a todos, eu estou usando o Adianti Studio pra gerar as classes, os forms e as listas. A listagem do código acima também foi gerada no Adianti Studio.
NR

No banco de dados você gravou somente o nome da imagem, desconsiderando a pasta?

Nesse caso tem que informar pasta + nome da imagem no TImage, senão o navegador vai buscar na raiz do projeto e não encontra a imagem.
PS

Nataniel, poderia mostrar no código acima onde e como colocar a pasta. Sou iniciante no Adianti e estou com dificuldades.
NR

Você deve informar o caminho no construtor da classe TImage:
  1. <?php
  2. $pasta 'tmp/'// supondo que a pasta seja tmp
  3. return new TImage($pasta $value);
  4. ?>
PS

Nataniel, consegui aqui, muito obrigado a você e todos que se empenharam neste post. Mais uma vez a família Adianti me deixou surpreso.