Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Tfieldlist - problema de carga Boa noite pessoal... Para variar sou mais um novato no framework, estou usaando o fieldlist para edição de tabelas, consultei o tutor e não consegui carregar dados do banco, o vetor recebe os dados e não transfere para o fieldlist segue o programa completo, se alguém pude me ajudar fico muito grato, ...
AT
Tfieldlist - problema de carga  
Boa noite pessoal...

Para variar sou mais um novato no framework, estou usaando o fieldlist para edição de tabelas, consultei o tutor e não consegui carregar dados do banco, o vetor recebe os dados e não transfere para o fieldlist segue o programa completo, se alguém pude me ajudar fico muito grato,

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


AT

  1. <?php
  2. /**
  3.  * EletronicosForm Master/Detail
  4.  * @author  <Antonio Augusto Tavares>
  5.  */
  6.  
  7. class EletronicosForm extends TPage
  8. {
  9.     protected $form// form
  10.     protected $detail_row;
  11.     protected $fieldlist;
  12.     private static $database 'setcis';
  13.     private static $activeRecord 'eletronicos';
  14.     private static $primaryKey 'id';
  15.     private static $formName 'form_eletronicos';
  16.     
  17.     /**
  18.      * Class constructor
  19.      * Creates the page and the registration form
  20.      */
  21.     function __construct($param)
  22.     {
  23.         parent::__construct($param);
  24.         
  25.         // creates the form
  26.         
  27.         $this->form = new TForm('my_form');
  28.                
  29.         $this->fieldlist = new TFieldList;
  30.         $this->fieldlist->name  'my_field_list';
  31.         $this->fieldlist->width '100%';
  32.         $this->fieldlist->enableSorting();
  33.         $this->form->add($this->fieldlist);
  34.         
  35.         $id = new TEntry('list_id[]');
  36.         $descricao = new TEntry('list_descricao[]');
  37.         $reduzido = new TEntry('list_reduzido[]');
  38.         $id->setSize('100%');
  39.         $descricao->setSize('100%');
  40.         $reduzido->setSize('100%');
  41.         $this->fieldlist->addField'<b>Id</b>'$id);
  42.         $this->fieldlist->addField'<b>Descrição</b>'$descricao);
  43.         $this->fieldlist->addField'<b>Reduzido</b>'$reduzido);
  44.         $this->form->addField($id);
  45.         $this->form->addField($descricao);
  46.         $this->form->addField($reduzido);
  47.         
  48.         // create an action button (save)
  49.         
  50.         $save TButton::create('save', [$this'onSave'], 'Save''fa:save blue');
  51.         $fill TButton::create('fill', [$this'onFill'], 'Fill''fa:pencil green');
  52.         
  53.         $this->form->addField($save);
  54.         $this->form->addField($fill);
  55.         
  56.         $panel = new TPanelGroup('Eletrônicos');
  57.         $panel->add($this->form);
  58.         $panel->addFooter(THBox::pack($save$fill));
  59.         
  60.         // create the page container
  61.         
  62.         $container = new TVBox;
  63.         $container->style 'width: 100%';
  64.         //$container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  65.         $container->add($panel);
  66.         
  67.         parent::add($container);
  68.     }
  69.     
  70.     /**
  71.      * Clear form
  72.      */
  73.      
  74.     public function onClear($param)
  75.     {
  76.         TFieldList::clear('my_field_list');
  77.         TFieldList::addRows('my_field_list'12);
  78.     }
  79.     
  80.      /**
  81.      * Fill data
  82.      */
  83.      
  84.    public function onfill$param )
  85.    {
  86.         try
  87.         {
  88.             TTransaction::open('setcis'); // open transaction
  89.             
  90.             $conn TTransaction::get(); // get PDO connection
  91.             
  92.             // run query
  93.             
  94.             $result $conn->query('SELECT id, descricao, reduzido from eletronicos order by id');
  95.             
  96.             // show results 
  97.  
  98.             $data = array();
  99.                
  100.             if ($result)
  101.             {
  102.                $this->fieldlist->addHeader();
  103.                
  104.                foreach($result  as $row )
  105.                {
  106.                
  107.                   //print $row['id'] . '-'; 
  108.                   //print $row['descricao'] . "<br>\n"; 
  109.                   $data['id']  = $row['id'];
  110.                   $data['descricao'] = $row['descricao'];
  111.                   $data['reduzido'] = $row['reduzido'];
  112.                   var_dump($data);
  113.                   
  114.                   $this->fieldlist->addDetail($data);
  115.                }
  116.                $this->fieldlist->addCloneAction();
  117.             }
  118.                       
  119.             TForm::sendData('my_form'$data);
  120.            //$this->form->setData($Data); // fill the form 
  121.            
  122.            // TForm::sendData('form_eletronicos', $Data); 
  123.            TTransaction::close(); // close the transaction 
  124.  
  125.         }
  126.         catch (Exception $e// in case of exception
  127.         {
  128.             new TMessage('error'$e->getMessage()); // shows the exception error message
  129.             TTransaction::rollback(); // undo all pending operations
  130.         }
  131.     }
  132.     
  133.     /**
  134.      * Save the Eletronicos
  135.      */
  136.      
  137.     public static function onSave($param)
  138.     {
  139.         try
  140.         {
  141.             TTransaction::open('setcis');
  142.             
  143.             if( !empty($param['list_id']) AND is_array($param['list_id']) )
  144.             {
  145.                 foreach( $param['list_id'] as $row => $id)
  146.                 {
  147.                     if (!empty($id))
  148.                     {
  149.                         $detail = new Eletronicos;
  150.                         $detail->id $param['list_id'][$row];
  151.                         $detail->descricao $param['list_descricao'][$row];
  152.                         $detail->reduzido $param['list_reduzido'][$row];
  153.                         $detail->store();
  154.                     }
  155.                 }
  156.             }
  157.             
  158.             TTransaction::close(); // close the transaction
  159.             
  160.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  161.         }
  162.         catch (Exception $e// in case of exception
  163.         {
  164.             new TMessage('error'$e->getMessage());
  165.             TTransaction::rollback();
  166.         }
  167.     }
  168. }
  169. </Antonio>