Passar um método na ação de um botão Senhores, bom dia; Estou tentando chamar uma método de uma classe na ação de um botão, porém sem sucesso. Alguém pode me ajudar ? segue abaixo código exemplo: erro esta na linha 81 ...
RB
Passar um método na ação de um botão  
Senhores, bom dia;

Estou tentando chamar uma método de uma classe na ação de um botão, porém sem sucesso.

Alguém pode me ajudar ?

segue abaixo código exemplo:

erro esta na linha 81

 
  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 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 $datagrid;
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. $this->form = new TForm;
  20. // creates one datagrid
  21. $this->datagrid = new TQuickGrid;
  22. $this->datagrid->disableDefaultClick(); // important!
  23. $this->form->add($this->datagrid);
  24. // add the columns
  25. $this->datagrid->addQuickColumn('Code', 'code', 'right', 70);
  26. $this->datagrid->addQuickColumn('Name', 'name', 'left', 180);
  27. $this->datagrid->addQuickColumn('Address', 'address', 'left', 180);
  28. $this->datagrid->addQuickColumn('Phone', 'fone', 'left', 120);
  29. $this->datagrid->addQuickColumn('', 'check', 'right', 8);
  30. $this->datagrid->addQuickColumn('', 'editar', 'right', 8);
  31. $this->datagrid->addQuickColumn('', 'deletar', 'right', 8);
  32. // creates the datagrid model
  33. $this->datagrid->createModel();
  34. // creates the action button
  35. $button1=new TButton('action1');
  36. // define the button action
  37. $button1->setAction(new TAction(array($this, 'onSave')), 'Save');
  38. $button1->setImage('ico_save.png');
  39. $this->form->addField($button1);
  40. // wrap the page content using vertical box
  41. $vbox = new TVBox;
  42. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  43. $vbox->add($this->form);
  44. $vbox->add($button1);
  45. parent::add($vbox);
  46. }
  47. /**
  48. * Load the data into the datagrid
  49. */
  50. function onReload()
  51. {
  52. $this->datagrid->clear();
  53. // add an regular object to the datagrid
  54. $item = new StdClass;
  55. $item->check = new TCheckButton('check1');
  56. $item->check->setIndexValue('on');
  57. $item->deletar = new TButton('deletar');
  58. $item->deletar->setImage('fa:trash red');
  59. $item->editar = new TButton('editar');
  60. $item->editar->setAction(new TAction(array('ClienteFisicoBuilder','onEdit')),'');
  61. //aqui esta dando erro
  62. //$item->editar->setAction(new TAction(array('ClienteFisicoBuilder#method=onClear','onEdit')),'');
  63. $item->editar->setImage('fa:edit blue');
  64. $item->code = '1';
  65. $item->name = 'Fábio Locatelli';
  66. $item->address = 'Rua Expedicionario';
  67. $item->fone = '1111-1111';
  68. $this->datagrid->addItem($item);
  69. $this->form->addField($item->check); // important!
  70. $this->form->addField($item->editar); // important!
  71. $this->form->addField($item->deletar); // important!
  72. // add an regular object to the datagrid
  73. $item = new StdClass;
  74. $item->check = new TCheckButton('check2');
  75. $item->check->setIndexValue('on');
  76. $item->code = '2';
  77. $item->name = 'Julia Haubert';
  78. $item->address = 'Rua Expedicionarios';
  79. $item->fone = '2222-2222';
  80. $this->datagrid->addItem($item);
  81. $this->form->addField($item->check); // important!
  82. // add an regular object to the datagrid
  83. $item = new StdClass;
  84. $item->check = new TCheckButton('check3');
  85. $item->check->setIndexValue('on');
  86. $item->code = '3';
  87. $item->name = 'Carlos Ranzi';
  88. $item->address = 'Rua Oliveira';
  89. $item->fone = '3333-3333';
  90. $this->datagrid->addItem($item);
  91. $this->form->addField($item->check); // important!
  92. // add an regular object to the datagrid
  93. $item = new StdClass;
  94. $item->check = new TCheckButton('check4');
  95. $item->check->setIndexValue('on');
  96. $item->code = '4';
  97. $item->name = 'Daline DallOglio';
  98. $item->address = 'Rua Oliveira';
  99. $item->fone = '4444-4444';
  100. $this->datagrid->addItem($item);
  101. $this->form->addField($item->check); // important!
  102. }
  103. /**
  104. * Simulates an save button
  105. * Show the form content
  106. */
  107. public function onSave($param)
  108. {
  109. $data = $this->form->getData(); // optional parameter: active record class
  110. // put the data back to the form
  111. $this->form->setData($data);
  112. // creates a string with the form element's values
  113. $message = 'Check 1 : ' . $data->check1 . '<br>';
  114. $message.= 'Check 2 : ' . $data->check2 . '<br>';
  115. $message.= 'Check 3 : ' . $data->check3 . '<br>';
  116. $message.= 'Check 4 : ' . $data->check4 . '<br>';
  117. // show the message
  118. new TMessage('info', $message);
  119. }
  120. /**
  121. * shows the page
  122. */
  123. function show()
  124. {
  125. $this->onReload();
  126. parent::show();
  127. }
  128. function onInative()
  129. {
  130. }
  131. function onEdit()
  132. {
  133. }
  134. }

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


LC

Tenta assim: $item->editar->setAction(new TAction(array('ClienteFisicoBuilder','onClear')),'');
RB

Opa, leandro valeu,

Aproveitando o gancho verificar se pode me ajudar, estou tentado personalizar a grid e colocar os botoes do lado direito, porém ao trazer as informações do banco os ícones não são adicionado.

segue trecho abaixo modificado.

 
  1. <?php
  2. function onReload($param )
  3. {
  4. $this->datagrid->clear();
  5. try{
  6. //abre a transação com a base
  7. TTransaction::open('teste');
  8. //cria um repositório para carregar 'Cliente Fisico'
  9. $cliente = new TRepository('VwClienteFisico');
  10. $limit = 10;
  11. //cria um critério para filtrar os dados conforme usuário logado
  12. $criteria = new TCriteria;
  13. // default order
  14. if (empty($param['order']))
  15. {
  16. $param['order'] = 'id';
  17. $param['direction'] = 'desc';
  18. }
  19. $get_session = TSession::getValue('organizacion_id');//pega id da empresa na seção do usuário
  20. $criteria->setProperties($param); // order, offset
  21. $criteria->add(new TFilter('organizacao_id', '=', $get_session));
  22. //$criteria->add(new TFilter('tipo_pessoa_id', '=', '1'));
  23. $criteria->setProperty('limit',$limit);
  24. $objects = $cliente->load($criteria);
  25. if($objects)
  26. {
  27. foreach($objects as $object)
  28. {
  29. // create delete button
  30. $del = new TImage('fa:edit blue');
  31. $this->datagrid->addItem($object);
  32. }
  33. }
  34. TTransaction::close();
  35. $this->loaded = TRUE;
  36. }
  37. catch (Exception $e)
  38. {
  39. new TMessage('error',$e->getMessage());
  40. TTransaction::rollback();
  41. }
  42. ?>
LC

Rubens, nunca fiz isso. Deixo sempre do lado esquerdo mesmo.
RB

Leandro,
beleza, valeu .
NR

Rubens, você precisar atribuir os botões aos objetos adicionados na grid:
 
  1. <?php
  2. // construtor
  3. $this->datagrid->addQuickColumn('', 'editar', 'right', 8);
  4. $this->datagrid->addQuickColumn('', 'deletar', 'right', 8);
  5. // onReload
  6. foreach($objects as $object)
  7. {
  8. $del = new TImage('fa:edit blue');
  9. $object->deletar = $del; //o nome do atributo deve corresponder ao segundo parametro do addQuickColumn
  10. $object->editar = 'teste';
  11. $this->datagrid->addItem($object);
  12. }
  13. ?>
RB

Nataniel,

Mais uma vez muito obrigado, funcionou perfeito.

Valeu.
RB

Nataniel,

Como atribuir / chamar um método neste botão

 
  1. <?php
  2. // onReload
  3. foreach($objects as $object)
  4. {
  5. $del = new TImage('fa:edit blue');
  6. $object->deletar = $del; //o nome do atributo deve corresponder ao segundo parametro do addQuickColumn
  7. $object->editar = 'teste';
  8. $this->datagrid->addItem($object);
  9. }
  10. ?>