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

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


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