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_SOCIAL, 200 );
  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. use Adianti\\Base\\AdiantiStandardFormTrait; // Standard form methods
  10. /**
  11. * Class constructor
  12. * Creates the page and the registration form
  13. */
  14. function __construct()
  15. {
  16. parent::__construct();
  17. $this->setDatabase('conexao'); // defines the database
  18. $this->setActiveRecord('Cliente'); // defines the active record
  19. // creates the form
  20. $this->form = new TQuickForm('form_Cliente');
  21. $this->form->class = 'tform'; // change CSS class
  22. $this->form->style = 'display: table;width:100%'; // change style
  23. //$this->form->style = 'display:-webkit-border-radius: 10px 20px'; // change style
  24. // define the form title
  25. $this->form->setFormTitle('Detalhes do Cliente');
  26. //$this->CODIGO = new TLabel;
  27. // $CODIGO = new TLabel('CODIGO');
  28. //$CODIGO->setEditable(FALSE);
  29. //$cod = new TEntry('codigo');
  30. /*$RAZAO_SOCIAL = new TEntry('RAZAO_SOCIAL');
  31. $NOME_FANTASIA = new TEntry('NOME_FANTASIA');
  32. $ENDERECO = new TEntry('ENDERECO');
  33. $NUMERO = new TEntry('NUMERO');
  34. $COMPLEMENTO = new TEntry('COMPLEMENTO');
  35. $BAIRRO = new TEntry('BAIRRO');
  36. $ID_CIDADE = new TEntry('ID_CIDADE');
  37. $FONE = new TEntry('FONE');
  38. $FAX = new TEntry('FAX');
  39. $CELULAR = new TEntry('CELULAR');
  40. $CONTATO = new TEntry('CONTATO');
  41. $CNPJ = new TEntry('CNPJ');
  42. $INSCRICAO = new TEntry('INSCRICAO');
  43. $EMAIL = new TEntry('EMAIL');
  44. $CPF = new TEntry('CPF');
  45. $IDENTIDADE = new TEntry('IDENTIDADE');*/
  46. // add the fields
  47. $this->form->addQuickField('Codigo:',$CODIGO, 900 );
  48. $this->form->addQuickFields('Texto1', array(new TLabel('Texto2'), new TLabel('Texto3'))); // create the form fields
  49. /* $this->form->addQuickField('Razao Social', $RAZAO_SOCIAL, 200 );
  50. $this->form->addQuickField('Nome Fantasia', $NOME_FANTASIA, 200 );
  51. $this->form->addQuickField('Endereco', $ENDERECO, 200 );
  52. $this->form->addQuickField('Numero', $NUMERO, 200 );
  53. $this->form->addQuickField('Complemento', $COMPLEMENTO, 200 );
  54. $this->form->addQuickField('Bairro', $BAIRRO, 200 );
  55. $this->form->addQuickField('Id Cidade', $ID_CIDADE, 100 );
  56. $this->form->addQuickField('Fone', $FONE, 200 );
  57. $this->form->addQuickField('Fax', $FAX, 200 );
  58. $this->form->addQuickField('Celular', $CELULAR, 200 );
  59. $this->form->addQuickField('Contato', $CONTATO, 200 );
  60. $this->form->addQuickField('Cnpj', $CNPJ, 200 );
  61. $this->form->addQuickField('Inscricao', $INSCRICAO, 200 );
  62. $this->form->addQuickField('Email', $EMAIL, 200 );
  63. $this->form->addQuickField('Cpf', $CPF, 200 );
  64. $this->form->addQuickField('Identidade', $IDENTIDADE, 200 );*/
  65. //$this->form->addQuickFields('Texto1', array(new TLabel('Texto2'), new TLabel('Texto3')));
  66. if (!empty($ID_CLIENTE))
  67. {
  68. $ID_CLIENTE->setEditable(FALSE);
  69. }
  70. /** samples
  71. $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  72. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  73. $fieldX->setSize( 100, 40 ); // set size
  74. **/
  75. // create the form actions
  76. //$this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  77. //$this->form->addQuickAction(_t('New'), new TAction(array($this, 'onEdit')), 'bs:plus-sign green');
  78. // vertical box container
  79. $container = new TVBox;
  80. $container->style = 'width: 100%';
  81. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  82. $container->add($this->form);
  83. parent::add($container);
  84. }
  85. }
  86. 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. public function get_situacao_cli()
  8. {
  9. $nomes = array('A'=>'Ativo', 'B'=>'Bloqueado','I'=>'Inativo');
  10. return $nomes[$this->SITUACAO];
  11. }
  12. public function set_unidadefederacao(Cidade $object)
  13. {
  14. $this->unidadefederacao = $object;
  15. $this-> ID_CIDADE= $object->ID; //Seu erro está aqui!!! ***
  16. }
  17. public function get_unidadefederacao()
  18. {
  19. // loads the associated object
  20. if (empty($this->unidadefederacao))
  21. $this->unidadefederacao = new cidade($this->ID_CIDADE); // E aqui!!!***
  22. // returns the associated object
  23. return $this->unidadefederacao;
  24. }
  25. }
  26. ?>




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