Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TCheckButton dinamico galera tenho o seguinte metodo ...
AS
TCheckButton dinamico  
Fechado
galera tenho o seguinte metodo

  1. <?php 
  2.      function onReload($param)
  3.         {
  4.             if (PHP_SAPI == 'cli')
  5.             {
  6.                 new TMessage('error''Web ONLY');
  7.                 return;
  8.             }
  9.             $this->datagrid->clear();
  10.             try{
  11.                 TTransaction::open('mysql');
  12.     $repo = new TRepository('Baixas');
  13.     $criteria = new TCriteria();
  14.     $criteria->add(new TFilter('venda_id','=',$param['key']));
  15.     $baixas $repo->load($criteria);
  16.             foreach($baixas as $b){
  17.             // add an regular object to the datagrid
  18.             $item = new StdClass;
  19.             $item->check    = new TCheckButton($b->id);
  20.             $item->check->setIndexValue('on');
  21.             $item->numero     $b->numero;
  22.             $item->valor     $b->valor;
  23.             $item->estatus  $b->estatus;
  24.             $this->datagrid->addItem($item);
  25.             $this->formFields[] = $item->check;
  26.             $this->form->setFields($this->formFields);
  27.             }
  28.         }catch (ErrorException $e){
  29.             new TMessage('error',$e->getMessage());
  30.             }
  31.         }
  32.     ?>




como fasso para pegar esse checkButton de maneira dinamica?

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


AN

Se entendi bem, este exemplo do tutor pode te ajudar:

  1. <?php
  2. /**
  3.  * DatagridQuickView
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2013 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class DatagridCheckView extends TPage
  13. {
  14.     private $form;
  15.     private $formFields;
  16.     private $datagrid;
  17.     
  18.     public function __construct()
  19.     {
  20.         parent::__construct();
  21.         
  22.         $this->form = new TForm;
  23.         
  24.         // creates one datagrid
  25.         $this->datagrid = new TQuickGrid;
  26.         $this->datagrid->disableDefaultClick();
  27.         
  28.         $this->form->add($this->datagrid);
  29.         
  30.         // add the columns
  31.         $this->datagrid->addQuickColumn('Check',   'check',   'right'40);
  32.         $this->datagrid->addQuickColumn('Code',    'code',    'right'70);
  33.         $this->datagrid->addQuickColumn('Name',    'name',    'left'180);
  34.         $this->datagrid->addQuickColumn('Address''address''left'180);
  35.         $this->datagrid->addQuickColumn('Phone',   'fone',    'left'120);
  36.         
  37.         // creates the datagrid model
  38.         $this->datagrid->createModel();
  39.         
  40.         // creates the action button
  41.         $button1=new TButton('action1');
  42.         // define the button action
  43.         $button1->setAction(new TAction(array($this'onSave')), 'Save');
  44.         $button1->setImage('ico_save.png');
  45.         
  46.         $this->formFields[] = $button1;
  47.         $this->form->setFields($this->formFields);
  48.         
  49.         $table = new TTable;
  50.         $table->addRow()->addCell($this->form);
  51.         $table->addRow()->addCell($button1);
  52.         // add the datagrid to the page
  53.         parent::add($table);
  54.     }
  55.     
  56.     /**
  57.      * Load the data into the datagrid
  58.      */
  59.     function onReload()
  60.     {
  61.         if (PHP_SAPI == 'cli')
  62.         {
  63.             new TMessage('error''Web ONLY');
  64.             return;
  65.         }
  66.         
  67.         $this->datagrid->clear();
  68.         
  69.         // add an regular object to the datagrid
  70.         $item = new StdClass;
  71.         $item->check    = new TCheckButton('check1');
  72.         $item->check->setIndexValue('on');
  73.         $item->code     '1';
  74.         $item->name     'Fábio Locatelli';
  75.         $item->address  'Rua Expedicionario';
  76.         $item->fone     '1111-1111';
  77.         $this->datagrid->addItem($item);
  78.         
  79.         $this->formFields[] = $item->check;
  80.         $this->form->setFields($this->formFields);
  81.         
  82.         // add an regular object to the datagrid
  83.         $item = new StdClass;
  84.         $item->check  = new TCheckButton('check2');
  85.         $item->check->setIndexValue('on');
  86.         $item->code     '2';
  87.         $item->name     'Julia Haubert';
  88.         $item->address  'Rua Expedicionarios';
  89.         $item->fone     '2222-2222';
  90.         $this->datagrid->addItem($item);
  91.         $this->formFields[] = $item->check;
  92.         $this->form->setFields($this->formFields);
  93.         
  94.         // add an regular object to the datagrid
  95.         $item = new StdClass;
  96.         $item->check  = new TCheckButton('check3');
  97.         $item->check->setIndexValue('on');
  98.         $item->code     '3';
  99.         $item->name     'Carlos Ranzi';
  100.         $item->address  'Rua Oliveira';
  101.         $item->fone     '3333-3333';
  102.         $this->datagrid->addItem($item);
  103.         $this->formFields[] = $item->check;
  104.         $this->form->setFields($this->formFields);
  105.         
  106.         // add an regular object to the datagrid
  107.         $item = new StdClass;
  108.         $item->check  = new TCheckButton('check4');
  109.         $item->check->setIndexValue('on');
  110.         $item->code     '4';
  111.         $item->name     'Marcela Rossler';
  112.         $item->address  'Rua Oliveira';
  113.         $item->fone     '4444-4444';
  114.         $this->datagrid->addItem($item);
  115.         $this->formFields[] = $item->check;
  116.         $this->form->setFields($this->formFields);
  117.     }
  118.     
  119.     /**
  120.      * Simulates an save button
  121.      * Show the form content
  122.      */
  123.     public function onSave($param)
  124.     {
  125.         $data $this->form->getData(); // optional parameter: active record class
  126.         
  127.         // put the data back to the form
  128.         $this->form->setData($data);
  129.         
  130.         // creates a string with the form element's values
  131.         $message 'Check 1 : ' $data->check1 '<br>';
  132.         $message.= 'Check 2 : ' $data->check2 '<br>';
  133.         $message.= 'Check 3 : ' $data->check3 '<br>';
  134.         $message.= 'Check 4 : ' $data->check4 '<br>';
  135.         
  136.         // show the message
  137.         new TMessage('info'$message);
  138.     }
  139.     
  140.     /**
  141.      * shows the page
  142.      */
  143.     function show()
  144.     {
  145.         $this->onReload();
  146.         parent::show();
  147.     }
  148. }
  149. ?>
AS

ate tentei mas ai não mostra como pegar dinamicamente pq ai pega um por um


  1. <?php
  2.  $message 'Check 1 : ' $data->check1 '<br>'
  3. ?>


onde ta esse check1 tinha que usar o id

tipo

  1. <?php
  2.  $message 'Check 1 : ' $data->$key->id '<br>';
  3. ?>


mas assim não da certo também
PD

Oi Alexandre,

Na próxima versão, a classe TForm vai ter um método chamado getFields(). Você pode temporariamente adicioná-lo assim em TForm:
  1. <?php
  2.     public function getFields()
  3.     {
  4.         return $this->fields;
  5.     }
  6. ?>


Então, para retornar os campos dinamicamente fica fácil. Lembre-se de substituir TEntry pelo componente que vc está usando:
  1. <?php
  2.     public function onSave($param)
  3.     {
  4.         $data $this->form->getData(); // optional parameter: active record class
  5.         
  6.         // put the data back to the form
  7.         $this->form->setData($data);
  8.         
  9.         $message '';
  10.         foreach ($this->form->getFields() as $name => $field)
  11.         {
  12.             if ($field instanceof TEntry)
  13.             {
  14.                 $message .= $name: " $field->getValue() . '<br>';
  15.             }
  16.         }
  17.         
  18.         // show the message
  19.         new TMessage('info'$message);
  20.     }
  21. ?>


Por fim, não use somente o ID como nome do objeto em:
new TCheckButton($b->id)
Concatene uma string, como:
new TCheckButton('check_' . $b->id);

abraços,
Pablo