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


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