Lançado Adianti Framework 8.1!
Clique aqui para saber mais
Como preencher combo com dados da tabela COMO FACO PARA PREENCHER UM COMBO COM OS DADOS DE UM DETERMINADO CAMPO DE UMA TABELA...
LG
Como preencher combo com dados da tabela  
Fechado
COMO FACO PARA PREENCHER UM COMBO COM OS DADOS DE UM DETERMINADO CAMPO DE UMA TABELA

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


NR

Leonardo, já deu uma olhada no tutor? Nele você vai encontrar muitos exemplos, como este referente a sua dúvida:

adianti.com.br/framework_files/tutor/index.php?class=FormDBAutoSelec
LG

  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.         
  38.         $this->form->style 'display: table;width:100%'// change style
  39.         $this->form->setFormTitle('Cliente');
  40.        // $cliente = new Cliente(1);
  41. //echo $cliente->cidade->nome;
  42.         // create the form fields
  43.         //$CODIGO = new TCombo('CODIGO');
  44.   --> COLOQUEI AQUI :
  45.         $CODIGO = new TDBCombo('CODIGO''cliente''Código''CODIGO''ID_CLIENTE');
  46.         $RAZAO_SOCIAL = new TEntry('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.       
  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.    
  59.         
  60.         // keep the form filled during navigation with session data
  61.         $this->form->setDataTSession::getValue('Cliente_filter_data') );
  62.         
  63.         // add the search form actions
  64.         $this->form->addQuickAction(_t('Find'), new TAction(array($this'onSearch')), 'fa:search');
  65.         $this->form->addQuickAction(_t('New'),  new TAction(array('ClienteForm''onEdit')), 'bs:plus-sign green');
  66.         
  67.         // creates a DataGrid
  68.         $this->datagrid = new TDataGrid;
  69.          $this->datagrid->disableDefaultClick(); // important!
  70.         
  71.         $this->datagrid->style 'width: 100%';
  72.         $this->datagrid->setHeight(320);
  73.         // $this->datagrid->datatable = 'true';
  74.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  75.         
  76.         // creates the datagrid columns
  77.         $column_CODIGO = new TDataGridColumn('CODIGO''Código''center');
  78.         $column_RAZAO_SOCIAL = new TDataGridColumn('RAZAO_SOCIAL''Razão Social''left');
  79.         $column_CPF = new TDataGridColumn('CPF''CPF/CNPJ''center');
  80.         $column_CNPJ = new TDataGridColumn('CNPJ''CNPJ''center');    
  81.         $column_ID_CIDADE = new TDataGridColumn('unidadefederacao->DESCRICAO''Cidade''center');
  82.         $column_FONE = new TDataGridColumn('FONE''Telefone''center');
  83.         $column_SITUACAO = new TDataGridColumn('situacao_cli''Situação''center');
  84.          //$COL= compara_cpfcnpj( $column_CPF, $column_CNPJ );
  85.        // $column_CPFCNPJ = new TDataGridColumn( compara_cpfcnpj   , 'CPF/CNPJ', 'center');
  86. $column_CPF->setTransformer(function($value,$object){ 
  87. if ($value
  88. return $value
  89. else 
  90. return $object->CNPJ
  91. }); 
  92.         
  93.          //$action_edit = new TDataGridAction(array($this, 'onView'));
  94.         //$action->setUseButton(TRUE);
  95.         //$action->setButtonClass('btn btn-info');
  96.         //$this->datagrid->addQuickAction('View', $action_edit, 'ID_CLIENTE', 'fa:search');
  97.         
  98.         
  99.         
  100.         // add the columns to the DataGrid
  101.         $this->datagrid->addColumn($column_CODIGO);
  102.         $this->datagrid->addColumn($column_RAZAO_SOCIAL);
  103.         $this->datagrid->addColumn($column_CPF);
  104.        // $this->datagrid->addColumn($column_CNPJ);
  105.         $this->datagrid->addColumn($column_ID_CIDADE);
  106.         $this->datagrid->addColumn($column_FONE);
  107.         $this->datagrid->addColumn($column_SITUACAO);
  108.      
  109.      
  110.        
  111.         // creates the datagrid column actions
  112.         $order_CODIGO = new TAction(array($this'onReload'));
  113.         $order_CODIGO->setParameter('order''CODIGO');
  114.         $column_CODIGO->setAction($order_CODIGO);
  115.         
  116.         $order_RAZAO_SOCIAL = new TAction(array($this'onReload'));
  117.         $order_RAZAO_SOCIAL->setParameter('order''RAZAO_SOCIAL');
  118.         $column_RAZAO_SOCIAL->setAction($order_RAZAO_SOCIAL);
  119.         
  120.         // create EDIT action
  121.         $action_edit = new TDataGridAction(array('ClienteForm''onedit'));
  122.         //$action_edit->setUseButton(TRUE);
  123.         //$action_edit->setButtonClass('btn btn-default');
  124.         $action_edit->setLabel('+ Detalhes');
  125.        // $action_edit->setLabel(_t('Edit'));
  126.         $action_edit->setImage('ico_find.png');
  127.         $action_edit->setField('ID_CLIENTE');
  128.         $this->datagrid->addAction($action_edit);
  129.          //$this->datagrid->addQuickAction('View', $action_edit, 'ID_CLIENTE', 'fa:search');    
  130.         
  131.         
  132.         // create DELETE action
  133.         $action_del = new TDataGridAction(array($this'onDelete'));
  134.         //$action_del->setUseButton(TRUE);
  135.         //$action_del->setButtonClass('btn btn-default');
  136.         $action_del->setLabel(_t('Delete'));
  137.         $action_del->setImage('ico_delete.png');
  138.         $action_del->setField('ID_CLIENTE');
  139.         $this->datagrid->addAction($action_del);
  140.         
  141.        
  142.        
  143.     
  144.         
  145.         // create the datagrid model
  146.         $this->datagrid->createModel();
  147.         
  148.         // create the page navigation
  149.         $this->pageNavigation = new TPageNavigation;
  150.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  151.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  152.         
  153.         // vertical box container
  154.         $container = new TVBox;
  155.         $container->style 'width: 100%';
  156.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  157.         $container->add($this->form);
  158.         $container->add($this->datagrid);
  159.         $container->add($this->pageNavigation);
  160.         
  161.         parent::add($container);
  162.     }
  163.     
  164.     
  165. }
  166. </your>
LB

Já resolveu? Se não te mando um exemplo que fiz. Me retorna
LG

Sim ja resolvido obrigado amigo.