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:
Segue abaixo o código da Listagem de Categorias:
- <?php
- /**
- * PedCategoriasLista Listing
- * @author <your name here>
- */
- class PedCategoriasLista extends TPage
- {
- private $form; // form
- private $datagrid; // listing
- private $pageNavigation;
- private $formgrid;
- private $loaded;
- private $deleteButton;
- /**
- * Class constructor
- * Creates the page, the form and the listing
- */
- public function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_PedCategorias');
- $this->form->setFormTitle('PedCategorias');
- // create the form fields
- $id = new TEntry('id');
- $ds_categoria = new TEntry('ds_categoria');
- // add the fields
- $this->form->addFields( [ new TLabel('Código') ], [ $id ] );
- $this->form->addFields( [ new TLabel('Categoria') ], [ $ds_categoria ] );
- // set sizes
- $id->setSize('100%');
- $ds_categoria->setSize('100%');
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue('PedCategorias_filter_data') );
- // add the search form actions
- $btn = $this->form->addAction(_t('Find'), new TAction([$this, 'onSearch']), 'fa:search');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink(_t('New'), new TAction(['PedCategoriasForm', 'onEdit']), 'fa:plus green');
- // creates a Datagrid
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->datatable = 'true';
- // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
- // creates the datagrid columns
- $column_id = new TDataGridColumn('id', 'Código', 'right', 30);
- $column_ds_categoria = new TDataGridColumn('ds_categoria', 'Categoria', 'left');
- $column_img_catego = new TDataGridColumn('img_catego', 'Imagem', 'center');
- // add the columns to the DataGrid
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_ds_categoria);
- $this->datagrid->addColumn($column_img_catego);
- // creates the datagrid column actions
- $column_id->setAction(new TAction([$this, 'onReload']), ['order' => 'id']);
- $column_ds_categoria->setAction(new TAction([$this, 'onReload']), ['order' => 'ds_categoria']);
- // define the transformer method over image
- $column_ds_categoria->setTransformer( function($value, $object, $row) {
- return strtoupper($value);
- });
- // define the transformer method over image
- $column_img_catego->setTransformer( function($value, $object, $row) {
- if (file_exists($value)) {
- return new TImage($value);
- }
- });
- // create EDIT action
- $action_edit = new TDataGridAction(['PedCategoriasForm', 'onEdit']);
- //$action_edit->setUseButton(TRUE);
- //$action_edit->setButtonClass('btn btn-default');
- $action_edit->setLabel(_t('Edit'));
- $action_edit->setImage('fa:pencil-square-o blue fa-lg');
- $action_edit->setField('id');
- $this->datagrid->addAction($action_edit);
- // create DELETE action
- $action_del = new TDataGridAction(array($this, 'onDelete'));
- //$action_del->setUseButton(TRUE);
- //$action_del->setButtonClass('btn btn-default');
- $action_del->setLabel(_t('Delete'));
- $action_del->setImage('fa:trash-o red fa-lg');
- $action_del->setField('id');
- $this->datagrid->addAction($action_del);
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- $container->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
- parent::add($container);
- }
- /**
- * Inline record editing
- * @param $param Array containing:
- * key: object ID value
- * field name: object attribute to be updated
- * value: new attribute content
- */
- public function onInlineEdit($param)
- {
- try
- {
- // get the parameter $key
- $field = $param['field'];
- $key = $param['key'];
- $value = $param['value'];
- TTransaction::open('sispedidos'); // open a transaction with database
- $object = new PedCategorias($key); // instantiates the Active Record
- $object->{$field} = $value;
- $object->store(); // update the object in the database
- TTransaction::close(); // close the transaction
- $this->onReload($param); // reload the listing
- new TMessage('info', "Record Updated");
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Register the filter in the session
- */
- public function onSearch()
- {
- // get the search form data
- $data = $this->form->getData();
- // clear session filters
- TSession::setValue('PedCategoriasLista_filter_id', NULL);
- TSession::setValue('PedCategoriasLista_filter_ds_categoria', NULL);
- if (isset($data->id) AND ($data->id)) {
- $filter = new TFilter('id', '=', "$data->id"); // create the filter
- TSession::setValue('PedCategoriasLista_filter_id', $filter); // stores the filter in the session
- }
- if (isset($data->ds_categoria) AND ($data->ds_categoria)) {
- $filter = new TFilter('ds_categoria', 'like', "%{$data->ds_categoria}%"); // create the filter
- TSession::setValue('PedCategoriasLista_filter_ds_categoria', $filter); // stores the filter in the session
- }
- // fill the form with data again
- $this->form->setData($data);
- // keep the search data in the session
- TSession::setValue('PedCategorias_filter_data', $data);
- $param = array();
- $param['offset'] =0;
- $param['first_page']=1;
- $this->onReload($param);
- }
- /**
- * Load the datagrid with data
- */
- public function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'sispedidos'
- TTransaction::open('sispedidos');
- // creates a repository for PedCategorias
- $repository = new TRepository('PedCategorias');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if (TSession::getValue('PedCategoriasLista_filter_id')) {
- $criteria->add(TSession::getValue('PedCategoriasLista_filter_id')); // add the session filter
- }
- if (TSession::getValue('PedCategoriasLista_filter_ds_categoria')) {
- $criteria->add(TSession::getValue('PedCategoriasLista_filter_ds_categoria')); // add the session filter
- }
- // load the objects according to criteria
- $objects = $repository->load($criteria, FALSE);
- if (is_callable($this->transformCallback))
- {
- call_user_func($this->transformCallback, $objects, $param);
- }
- $this->datagrid->clear();
- if ($objects)
- {
- // iterate the collection of active records
- foreach ($objects as $object)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count= $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Ask before deletion
- */
- public static function onDelete($param)
- {
- // define the delete action
- $action = new TAction([__CLASS__, 'Delete']);
- $action->setParameters($param); // pass the key parameter ahead
- // shows a dialog to the user
- new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- /**
- * Delete a record
- */
- public static function Delete($param)
- {
- try
- {
- $key=$param['key']; // get the parameter $key
- TTransaction::open('sispedidos'); // open a transaction with database
- $object = new PedCategorias($key, FALSE); // instantiates the Active Record
- $object->delete(); // deletes the object from the database
- TTransaction::close(); // close the transaction
- $pos_action = new TAction([__CLASS__, 'onReload']);
- new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method show()
- * Shows the page
- */
- public function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
- {
- if (func_num_args() > 0)
- {
- $this->onReload( func_get_arg(0) );
- }
- else
- {
- $this->onReload();
- }
- }
- parent::show();
- }
- }
Paulo, altera esta linha:
Luis, fiz a alteração porém continua sem mostrar
Alguém mais pode dar uma ajuda?
Precisando com urgência...
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.
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.
Nataniel, poderia mostrar no código acima onde e como colocar a pasta. Sou iniciante no Adianti e estou com dificuldades.
Você deve informar o caminho no construtor da classe TImage:
Nataniel, consegui aqui, muito obrigado a você e todos que se empenharam neste post. Mais uma vez a família Adianti me deixou surpreso.