Lançado Adianti Framework 8.1!
Clique aqui para saber mais
Pegar valor na variavel php. Como Faço... Gostaria de saber como jogo numa variavel php o valor oriundo de uma coluna de uma tabela. Por exemplo: Ao inves de jogar no campo ( combo, entry, etc...) Jogar numa variavel ex:$ex. O objetivo e jogar a variavel numa tlabel. Estou encontrando uma dificuldade estou tremenda. .... ///$CODIGO = new THidden('CODIGO'); $cod=new TLabel($CODIGO); Bem confuso esse sistema em relação a i...
LG
Pegar valor na variavel php. Como Faço...  
Fechado
Gostaria de saber como jogo numa variavel php o valor oriundo de uma coluna de uma tabela.

Por exemplo:
Ao inves de jogar no campo ( combo, entry, etc...) Jogar numa variavel ex:$ex.
O objetivo e jogar a variavel numa tlabel. Estou encontrando uma dificuldade estou tremenda.

....
///$CODIGO = new THidden('CODIGO');
$cod=new TLabel($CODIGO);

Bem confuso esse sistema em relação a isso . Estou tendo ponto negativos a minha avaliação.

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (8)


FW

Leonardo,

Dependendo do componente que você estiver utilizando você pode usar o setLabel, ou um TLabel e add ele a um objeto.

$campo->setLabel($label);
LG

por exemplo:

$RAZAO_SOCIAL = new TEntry('RAZAO_SOCIAL');

eu quero( ao inves do TEntry):
$RAZAO_SOCIAL = new TLabel('RAZAO_SOCIAL');
continuando o codigo:
$this->form->addQuickField('Razao Social', $RAZAO_SOCIAL, 200 );

ele mostra:
RAZAO SOCIAL


o que eu quero e mostrar o por exemplo o nome ex: COMERCIO E CIA...num tlabel ao inves do tEntry
FW

Leonardo,

É um formulário de edição?
Você precisa fazer uma função que abra uma transação e busque o valor, para que você possa setar o valor antes de adicioná-lo ao formulário.
Depende da necessidade deste formulário, da tabela, se for edição será apenas 1 registro então é mais fácil.
  1. <?php
  2. $RAZAO_SOCIAL = new TLabel('RAZAO_SOCIAL'); 
  3. $RAZAO_SOCIAL_busca onBuscaRazao();
  4. $RAZAO_SOCIAL->setLabel($RAZAO_SOCIAL_busca);
  5. $this->form->addQuickField('Razao Social'$RAZAO_SOCIAL200 ); 
  6. ?>
LG

ele esta no arquivo :
ClienteForm.class.php

  1. <?php
  2. /**
  3.  * ClienteForm Registration
  4.  * @author  <your name here>
  5.  */
  6. class ClienteForm extends TWindow
  7. {
  8.     protected $form// form
  9.     
  10.     use Adianti\\Base\\AdiantiStandardFormTrait// Standard form methods
  11.     
  12.     /**
  13.      * Class constructor
  14.      * Creates the page and the registration form
  15.      */
  16.     function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         $this->setDatabase('conexao');              // defines the database
  21.         $this->setActiveRecord('Cliente');     // defines the active record
  22.         
  23.         // creates the form
  24.         $this->form = new TQuickForm('form_Cliente');
  25.         $this->form->class 'tform'// change CSS class
  26.         
  27.         $this->form->style 'display: table;width:100%'// change style
  28.          //$this->form->style = 'display:-webkit-border-radius: 10px 20px'; // change style
  29.         
  30.         // define the form title
  31.         $this->form->setFormTitle('Detalhes do Cliente');
  32.         
  33.         //$this->CODIGO = new TLabel; 
  34.       
  35.         
  36.        // $CODIGO = new TLabel('CODIGO'); 
  37.         //$CODIGO->setEditable(FALSE);
  38.         //$cod = new TEntry('codigo');
  39.  
  40.         
  41.         /*$RAZAO_SOCIAL = new TEntry('RAZAO_SOCIAL');
  42.         $NOME_FANTASIA = new TEntry('NOME_FANTASIA');
  43.         $ENDERECO = new TEntry('ENDERECO');
  44.         $NUMERO = new TEntry('NUMERO');
  45.         $COMPLEMENTO = new TEntry('COMPLEMENTO');
  46.         $BAIRRO = new TEntry('BAIRRO');
  47.         $ID_CIDADE = new TEntry('ID_CIDADE');
  48.         $FONE = new TEntry('FONE');
  49.         $FAX = new TEntry('FAX');
  50.         $CELULAR = new TEntry('CELULAR');
  51.         $CONTATO = new TEntry('CONTATO');
  52.         $CNPJ = new TEntry('CNPJ');
  53.         $INSCRICAO = new TEntry('INSCRICAO');
  54.         $EMAIL = new TEntry('EMAIL');
  55.         $CPF = new TEntry('CPF');
  56.         $IDENTIDADE = new TEntry('IDENTIDADE');*/
  57.      
  58.         // add the fields
  59.         
  60.        $this->form->addQuickField('Codigo:',$CODIGO900 );
  61.          $this->form->addQuickFields('Texto1', array(new TLabel('Texto2'), new TLabel('Texto3'))); // create the form fields
  62.        /* $this->form->addQuickField('Razao Social', $RAZAO_SOCIAL,  200 );
  63.         $this->form->addQuickField('Nome Fantasia', $NOME_FANTASIA,  200 );
  64.         $this->form->addQuickField('Endereco', $ENDERECO,  200 );
  65.         $this->form->addQuickField('Numero', $NUMERO,  200 );
  66.         $this->form->addQuickField('Complemento', $COMPLEMENTO,  200 );
  67.         $this->form->addQuickField('Bairro', $BAIRRO,  200 );
  68.         $this->form->addQuickField('Id Cidade', $ID_CIDADE,  100 );
  69.         $this->form->addQuickField('Fone', $FONE,  200 );
  70.         $this->form->addQuickField('Fax', $FAX,  200 );
  71.         $this->form->addQuickField('Celular', $CELULAR,  200 );
  72.         $this->form->addQuickField('Contato', $CONTATO,  200 );
  73.         $this->form->addQuickField('Cnpj', $CNPJ,  200 );
  74.         $this->form->addQuickField('Inscricao', $INSCRICAO,  200 );
  75.         $this->form->addQuickField('Email', $EMAIL,  200 );
  76.         $this->form->addQuickField('Cpf', $CPF,  200 );
  77.         $this->form->addQuickField('Identidade', $IDENTIDADE,  200 );*/
  78.     
  79. //$this->form->addQuickFields('Texto1', array(new TLabel('Texto2'), new TLabel('Texto3')));
  80.         
  81.         if (!empty($ID_CLIENTE))
  82.         {
  83.             $ID_CLIENTE->setEditable(FALSE);
  84.         }
  85.         
  86.         /** samples
  87.          $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  88.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  89.          $fieldX->setSize( 100, 40 ); // set size
  90.          **/
  91.          
  92.         // create the form actions
  93.         //$this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  94.         //$this->form->addQuickAction(_t('New'),  new TAction(array($this, 'onEdit')), 'bs:plus-sign green');
  95.         
  96.         // vertical box container
  97.         $container = new TVBox;
  98.         $container->style 'width: 100%';
  99.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  100.         $container->add($this->form);
  101.         
  102.         parent::add($container);
  103.     }
  104. }
  105. apartir do "clique da lupa da tabela e abre uma janela" que seria o arquivo acima </your>
LG

o arquivo que da tabela é:

ClienteList.class.php

  1. <?php
  2.  class Cliente extends TRecord
  3. {
  4.     const TABLENAME 'cliente';
  5.     const PRIMARYKEY'id';
  6.     const IDPOLICY =  'max'// {max, serial}
  7.     
  8.     public function get_situacao_cli()
  9.     {
  10.         $nomes = array('A'=>'Ativo''B'=>'Bloqueado','I'=>'Inativo');
  11.         return $nomes[$this->SITUACAO];
  12.     }
  13.     
  14.       public function set_unidadefederacao(Cidade $object)
  15.     {
  16.         $this->unidadefederacao $object;
  17.         $this-> ID_CIDADE$object->ID;  //Seu erro está aqui!!! ***
  18.     }
  19.     
  20.       public function get_unidadefederacao()
  21.     {
  22.         // loads the associated object
  23.         if (empty($this->unidadefederacao))
  24.             $this->unidadefederacao = new cidade($this->ID_CIDADE); // E aqui!!!***
  25.     
  26.         // returns the associated object
  27.         return $this->unidadefederacao;
  28.     }
  29.     
  30.     
  31.     
  32. ?>




  1. <?php
  2. /**
  3.  * ClienteList Listing
  4.  * @author  <your name here>
  5.  */
  6. class ClienteList 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('conexao');            // defines the database
  23.         parent::setActiveRecord('Cliente');   // defines the active record
  24.         parent::setDefaultOrder('ID_CLIENTE''asc');         // defines the default order
  25.         // parent::setCriteria($criteria) // define a standard filter
  26.         parent::addFilterField('CODIGO''=''CODIGO'); // filterField, operator, formField
  27.         parent::addFilterField('RAZAO_SOCIAL''like''RAZAO_SOCIAL'); // filterField, operator, formField
  28.         parent::addFilterField('CPF''like''CPF'); // filterField, operator, formField
  29.         parent::addFilterField('CNPJ''like''CNPJ'); // filterField, operator, formField
  30.         parent::addFilterField('ID_CIDADE''like''ID_CIDADE'); // filterField, operator, formField
  31.         parent::addFilterField('FONE''like''FONE'); // filterField, operator, formField
  32.         parent::addFilterField('SITUACAO''like''SITUACAO'); // filterField, operator, formField
  33.       
  34.         // creates the form
  35.         $this->form = new TQuickForm('form_search_Cliente');
  36.         $this->form->class 'tform'// change CSS class
  37.         $this->form->style 'display: table;width:100%;-moz-border-radius: 10px'// change style
  38.          
  39.         $this->form->setFormTitle('Cadastro de Clientes');
  40.        // $cliente = new Cliente(1);
  41. //echo $cliente->cidade->nome;
  42.         // create the form fields
  43.         //$CODIGO = new TCombo('CODIGO');
  44.         $CODIGO = new TDBCombo('CODIGO''conexao''Cliente''CODIGO''CODIGO');
  45.        // $RAZAO_SOCIAL = new TEntry('RAZAO_SOCIAL');
  46.         $RAZAO_SOCIAL = new TDBEntry('RAZAO_SOCIAL''conexao''Cliente''RAZAO_SOCIAL');
  47.         $CPF = new TEntry('CPF');
  48.         $CNPJ = new TEntry('CNPJ');
  49.       //  $ID_CIDADE = new TEntry('ID_CIDADE');
  50.         $FONE = new TEntry('FONE');
  51.         //$SITUACAO = new TEntry('SITUACAO');
  52.         $SITUACAO = new TCombo('SITUACAO');
  53.      
  54. $SITUACAO->addItems(array( 'A'=>'Ativo'
  55. 'B'=>'Bloqueado'
  56. 'I'=>'Inativo'
  57. )); 
  58.      
  59.         // add the fields
  60.         $this->form->addQuickField('Código:'$CODIGO,  600 );
  61.         $this->form->addQuickField('Razão Social:'$RAZAO_SOCIAL,  600 );
  62.         $this->form->addQuickField('CPF/CNPJ:'$CPF,  600 );
  63.         $this->form->addQuickField('Situação:'$SITUACAO,  600 );
  64.    
  65.         
  66.         // keep the form filled during navigation with session data
  67.         $this->form->setDataTSession::getValue('Cliente_filter_data') );
  68.         
  69.         // add the search form actions
  70.         $this->form->addQuickAction(_t('Find'), new TAction(array($this'onSearch')), 'fa:search');
  71.         $this->form->addQuickAction(_t('New'),  new TAction(array('ClienteForm''onEdit')), 'bs:plus-sign green');
  72.         
  73.         // creates a DataGrid
  74.         $this->datagrid = new TDataGrid;
  75.          $this->datagrid->disableDefaultClick(); // important!
  76.         
  77.         $this->datagrid->style 'width: 100%';
  78.         $this->datagrid->setHeight(320);
  79.         // $this->datagrid->datatable = 'true';
  80.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  81.         
  82.         // creates the datagrid columns
  83.         $column_CODIGO = new TDataGridColumn('CODIGO''Código''center');
  84.         $column_RAZAO_SOCIAL = new TDataGridColumn('RAZAO_SOCIAL''Razão Social''left');
  85.         $column_CPF = new TDataGridColumn('CPF''CPF/CNPJ''center');
  86.         $column_CNPJ = new TDataGridColumn('CNPJ''CNPJ''center');    
  87.         $column_ID_CIDADE = new TDataGridColumn('unidadefederacao->DESCRICAO''Cidade''center');
  88.         $column_FONE = new TDataGridColumn('FONE''Telefone''center');
  89.         $column_SITUACAO = new TDataGridColumn('situacao_cli''Situação''center');
  90.          //$COL= compara_cpfcnpj( $column_CPF, $column_CNPJ );
  91.        // $column_CPFCNPJ = new TDataGridColumn( compara_cpfcnpj   , 'CPF/CNPJ', 'center');
  92. $column_CPF->setTransformer(function($value,$object){ 
  93. if ($value
  94. return $value
  95. else 
  96. return $object->CNPJ
  97. }); 
  98.         
  99.          //$action_edit = new TDataGridAction(array($this, 'onView'));
  100.         //$action->setUseButton(TRUE);
  101.         //$action->setButtonClass('btn btn-info');
  102.         //$this->datagrid->addQuickAction('View', $action_edit, 'ID_CLIENTE', 'fa:search');
  103.         
  104.         
  105.         
  106.         // add the columns to the DataGrid
  107.         $this->datagrid->addColumn($column_CODIGO);
  108.         $this->datagrid->addColumn($column_RAZAO_SOCIAL);
  109.         $this->datagrid->addColumn($column_CPF);
  110.        // $this->datagrid->addColumn($column_CNPJ);
  111.         $this->datagrid->addColumn($column_ID_CIDADE);
  112.         $this->datagrid->addColumn($column_FONE);
  113.         $this->datagrid->addColumn($column_SITUACAO);
  114.      
  115.      
  116.        
  117.         // creates the datagrid column actions
  118.         $order_CODIGO = new TAction(array($this'onReload'));
  119.         $order_CODIGO->setParameter('order''CODIGO');
  120.         $column_CODIGO->setAction($order_CODIGO);
  121.         
  122.         $order_RAZAO_SOCIAL = new TAction(array($this'onReload'));
  123.         $order_RAZAO_SOCIAL->setParameter('order''RAZAO_SOCIAL');
  124.         $column_RAZAO_SOCIAL->setAction($order_RAZAO_SOCIAL);
  125.         
  126.         // create EDIT action
  127.         $action_edit = new TDataGridAction(array('ClienteForm''onedit'));
  128.         //$action_edit->setUseButton(TRUE);
  129.         //$action_edit->setButtonClass('btn btn-default');
  130.         $action_edit->setLabel('+ Detalhes');
  131.        // $action_edit->setLabel(_t('Edit'));
  132.         $action_edit->setImage('ico_find.png');
  133.         $action_edit->setField('ID_CLIENTE');
  134.         $this->datagrid->addAction($action_edit);
  135.          //$this->datagrid->addQuickAction('View', $action_edit, 'ID_CLIENTE', 'fa:search');    
  136.         
  137.         
  138.         // create DELETE action
  139.         $action_del = new TDataGridAction(array($this'onDelete'));
  140.         //$action_del->setUseButton(TRUE);
  141.         //$action_del->setButtonClass('btn btn-default');
  142.         $action_del->setLabel(_t('Delete'));
  143.         $action_del->setImage('ico_delete.png');
  144.         $action_del->setField('ID_CLIENTE');
  145.         $this->datagrid->addAction($action_del);
  146.         
  147.        
  148.        
  149.     
  150.         
  151.         // create the datagrid model
  152.         $this->datagrid->createModel();
  153.         
  154.         // create the page navigation
  155.         $this->pageNavigation = new TPageNavigation;
  156.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  157.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  158.         
  159.         // vertical box container
  160.         $container = new TVBox;
  161.         $container->style 'width: 100%';
  162.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  163.         $container->add($this->form);
  164.         $container->add($this->datagrid);
  165.         $container->add($this->pageNavigation);
  166.         
  167.         parent::add($container);
  168.     }
  169.     
  170.  
  171. }
  172.          </your>
LG

  1. <?php
  2. $RAZAO_SOCIAL = new TLabel('RAZAO_SOCIAL'); 
  3. $RAZAO_SOCIAL_busca onBuscaRazao();
  4. $RAZAO_SOCIAL->setLabel($RAZAO_SOCIAL_busca);
  5. $this->form->addQuickField('Razao Social'$RAZAO_SOCIAL200 ); 
  6. ?>


da na mesma. o resultado sera RAZAO SOCIAL.


O que nao entendo qual a diferenca de TEntry pra TLabel. Pela logica sera mesma coisa...
IF

Uma pergunta Leonardo: Vc vai apenas mostrar os dados ou também vai ter campos para edição?
IF

Se for só pra mostrar os dados, vc pode colocar isso numa tabela e não num Form.
  1. <?php
  2. class VisualizaCliente extends TWindow
  3. {
  4.     public function __construct()
  5.     {
  6.         parent::__construct();
  7.         
  8.         TTransaction::open('database');
  9.         
  10.         $clientes = new clientes('1');
  11.         
  12.         $tabela = new TTable;
  13.         $tabela->addRowSet('Codigo:'$clientes->id);
  14.         $tabela->addRowSet('Nome:'$clientes->nome);
  15.         $tabela->addRowSet('Telefone:'$clientes->telefone);
  16.         
  17.         parent::add($tabela);
  18.         
  19.         TTransaction::close();
  20.     }    
  21. }
  22. ?>