Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Meu Form não vai para a funcao onSearch !!! Pessoal , estou com muita dificuldade nesta pagina. criei um form e tambem uma página com replace html. quero que ao clicar no botao Buscar, ele vá para a função onSearch. Outro erro que acontece é que a imagem do evento esta aparecendo 2x quando vou para a proxima pagina do pageNavigation. ...
LJ
Meu Form não vai para a funcao onSearch !!!  
Pessoal , estou com muita dificuldade nesta pagina. criei um form e tambem uma página com replace html.
quero que ao clicar no botao Buscar, ele vá para a função onSearch.
Outro erro que acontece é que a imagem do evento esta aparecendo 2x quando vou para a proxima pagina do pageNavigation.
  1. <?php
  2. class FrontCategoria extends TPage
  3. {
  4.     /**
  5.      * Constructor method
  6.      */
  7.      //public $busca;
  8.     private $html;
  9.     private $pageNavigation;
  10.     private $form
  11.      
  12.     public function __construct()
  13.     {
  14.         parent::__construct();
  15.     
  16.         // load the styles
  17.         TPage::include_css('app/resources/css/animate.css');
  18.         TPage::include_css('app/resources/css/bootstrap.min.css');
  19.         TPage::include_js('app/resources/js/jquery-2.2.0.min.js');
  20.         TPage::include_js('app/resources/js/bootstrap.min.js');
  21.         TPage::include_js('app/resources/js/wow.min.js');
  22.         TPage::include_css('app/resources/categoria.css');
  23.         
  24.         $this->form = new TQuickForm;
  25.         $this->form->class 'tform';
  26.         $this->form->setFormTitle('Evento');
  27.         // create the form fields
  28.         $nome        = new TEntry('nome');
  29.         $dataevento  = new TDate('dataevento');
  30.         $busca       = new TEntry('busca');
  31.         
  32.         //$imagem->setEditable( FALSE ); 
  33.         $nome->setEditableFALSE ); 
  34.         $dataevento->setEditableFALSE ); 
  35.         $this->frame = new TElement('div');
  36.         $this->frame->id 'photo_frame';
  37.         $this->frame->style 'width:140px;height:auto;min-height:140px;border:1px solid gray;padding:4px;';
  38.         $row $this->form->addRow();
  39.         $row->addCell('');
  40.         $row->addCell($this->frame);
  41.         
  42.         $this->form->addQuickField('Nome'$nome,  200);
  43.         $this->form->addQuickField('Data'$dataevento,  100);
  44.         $this->form->addQuickField('Número de Peito'$busca100);
  45.         
  46.         // define the form action 
  47.         $this->form->addQuickAction('Buscar', new TAction(array($this'onSearch')), 'fa:check-circle-o green');        
  48.     
  49.         // create the HTML Renderer
  50.         $this->html = new THtmlRenderer('app/resources/categoria.html');
  51.         
  52.             // define replacements for the main section
  53.             //  Produtos
  54.         $replace = array();
  55.         $this->html->enableSection('main'$replace);
  56.         
  57.         $this->enableManagement();
  58.             // creates the page navigation
  59.         $this->pageNavigation = new TPageNavigation;
  60.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));        
  61.             
  62.             // wrap the page content using vertical box
  63.         $vbox = new TVBox;
  64.         $vbox->add($this->form);
  65.         $vbox->add($this->html);
  66.         $vbox->add($this->pageNavigation);
  67.         parent::add($vbox);            
  68.     }
  69.     /**
  70.      * Enable or not the 'manage' section
  71.      */
  72.     public function enableManagement()
  73.     {
  74.         if (is_array(TSession::getValue('cart_items')) AND count(TSession::getValue('cart_items')) > 0)
  75.         {
  76.             $this->html->enableSection('manage');
  77.         }
  78.     }    
  79.     /**
  80.      * Executed when the user clicks at click to buy button
  81.      */
  82.     public function onComprar$param )
  83.     {
  84.         $cart_items TSession::getValue('cart_items');
  85.         $i=count($cart_items);
  86.         $cart_items[$i]['produto_id'] =  $param['produto_id'] ;
  87.         $cart_items[$i]['preco_id'] =  $param['preco_id'] ;
  88.         
  89.         TSession::setValue('cart_items'$cart_items);
  90.         new TMessage('info','Voce inseriu um produto no carrinho de compras');
  91.         //$i++;
  92.         $this->enableManagement();
  93.         
  94.         // acrescentar no carrinho visual
  95.     }    
  96.     function onEdit$param )
  97.     {
  98.             TSession::setValue('categoria'$param['key']);
  99.     }
  100.     /**
  101.      * Fill the html template with objects
  102.      */
  103.     public function onReload$param NULL )
  104.     {
  105.         try
  106.         {
  107.             $limit 16;
  108.             // recarrega o form
  109.             TTransaction::open('ecommerce');
  110.             $categoria= new Categoria(TSession::getValue('categoria'));
  111.             $categoria->dataevento TDate::date2br($categoria->dataevento);
  112.                 if ((isset($param['busca'])) AND ($param['busca'])){
  113.                     $filter = new TFilter('busca''like'"%-{$param['busca']}-%");
  114.                     TSession::setValue('busca_filter1'$filter);
  115.                     $busca TSession::setValue('busca'$param['busca']);
  116.                     new TMessage('info','118');
  117.                 }else{
  118.                     TSession::setValue('busca_filter1'NULL);
  119.                     $busca TSession::setValue('busca''');
  120.                 }
  121.                 $obj = new stdClass();
  122.                 $obj->dataevento $categoria->dataevento;
  123.                 $obj->nome $categoria->nome;
  124.                 $obj->busca $busca;
  125.                 $this->form->setData($obj);
  126.                 if ($categoria)
  127.                         {
  128.                             $imagem = new TImage($categoria->imagem);
  129.                             $imagem->style 'width: 100%';
  130.                             $this->frame->add($imagem);
  131.                         }
  132.             // recareca a pagina dos produtos            
  133.             $criteria = new TCriteria;
  134.             $criteria->add(new TFilter('categoria_id','=',TSession::getValue('categoria')));
  135.             if (TSession::getValue('busca_filter1'))
  136.             {
  137.                 $criteria->add(TSession::getValue('busca_filter1'));
  138.                 
  139.             }
  140.             $criteria->setProperties($param); // order, offset
  141.             $criteria->setProperty('limit'$limit);
  142.             
  143.             $produtos_todos Produto::getObjects($criteria);
  144.             $criteria->resetProperties(); // reset the criteria for record count
  145.             $countProduto::countObjects($criteria);
  146.             
  147.                         
  148.             
  149.             $replace = array();
  150.             if($produtos_todos)
  151.             {
  152.             $i=0;
  153.             foreach ($produtos_todos as $produto_categoria)
  154.             {
  155.             $replace['produto'][$i]['id']=    $produto_categoria->id;    
  156.             $replace['produto'][$i]['imagem']=      $produto_categoria->imagem;    
  157.             //programar nome da corrida
  158.             $replace['produto'][$i]['evento']=      'nome da corrida';
  159.             $precos $produto_categoria->getPrecos();
  160.             $x=0
  161.             foreach ($precos as $preco)
  162.                 {
  163.                     $replace['produto'][$i]['preco'][$x]['id']=    $produto_categoria->id;    
  164.                     $replace['produto'][$i]['preco'][$x]['preco_id']=$preco->id;
  165.                     $replace['produto'][$i]['preco'][$x]['valor']=' R$ '.$preco->preco.'  Tamanho: '.$preco->tamanho;
  166.                     $x++;
  167.                 }            
  168.             $i++;            
  169.             }
  170.             TTransaction::close();    
  171.             }
  172.             
  173.             // replace the main section variables
  174.             $this->html->enableSection('main'$replace);
  175.    
  176.             $this->pageNavigation->setCount($count); // count of records
  177.             $this->pageNavigation->setProperties($param); // order, page
  178.             $this->pageNavigation->setLimit($limit); // limit
  179.         }
  180.         catch (Exception $e)
  181.         {
  182.             new TMessage('error'$e->getMessage());
  183.         }
  184.     }
  185.     /**
  186.      * Simulates an save button
  187.      * Show the form content
  188.      */
  189.     function onSearch()
  190.     {
  191.         new TMessage('info','linha 210');
  192.         $data $this->form->getData(); // optional parameter: active record class
  193.         
  194.         // put the data back to the form
  195.         //$this->form->setData($data);
  196.     
  197.     }
  198.     
  199.     public function show()
  200.     {
  201.         $this->onReloadfunc_get_arg(0) );
  202.         parent::show();
  203.     }    
  204.     
  205. }
  206. ?>

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


LJ

Criei uma classe ProductCatalogView2 , da mesma maneira que pretendo fazer acima e funciona, porem no meu exemplo nao funciona, podem colocar esta nova classe dentro do tutor que vai funcionar.
  1. <?php
  2. /**
  3.  * Product catalog
  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 ProductCatalogView2 extends TPage
  13. {
  14.     private $html;
  15.     private $pageNavigation;
  16.     
  17.     private $form;
  18.        
  19.     /**
  20.      * Constructor method
  21.      */
  22.     public function __construct()
  23.     {
  24.         parent::__construct();
  25.         
  26.         // load the styles
  27.         TPage::include_css('app/resources/catalog.css');
  28.  
  29.         $this->form = new TQuickForm;
  30.         $this->form->class 'tform';
  31.         $this->form->setFormTitle('Evento');
  32.         $busca       = new TEntry('busca');
  33.         $this->form->addQuickField('Descrição'$busca100);
  34.         // define the form action 
  35.         $this->form->addQuickAction('Buscar', new TAction(array($this'onSearch')), 'fa:check-circle-o green');            
  36.  
  37.         // create the HTML Renderer
  38.         $this->html = new THtmlRenderer('app/resources/catalog.html');
  39.         // define replacements for the main section
  40.         $replace = array();
  41.         
  42.         // replace the main section variables
  43.         $this->html->enableSection('main'$replace);
  44.         
  45.         $this->enableManagement();
  46.         
  47.         // creates the page navigation
  48.         $this->pageNavigation = new TPageNavigation;
  49.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  50.         
  51.         // wrap the page content using vertical box
  52.         $vbox = new TVBox;
  53.         $vbox->add($this->form);
  54.         //$vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  55.         $vbox->add($this->html);
  56.         $vbox->add($this->pageNavigation);
  57.         parent::add($vbox);
  58.     }
  59.     
  60.     /**
  61.      * Enable or not the 'manage' section
  62.      */
  63.     public function enableManagement()
  64.     {
  65.         if (is_array(TSession::getValue('cart_items')) AND count(TSession::getValue('cart_items')) > 0)
  66.         {
  67.             $this->html->enableSection('manage');
  68.         }
  69.     }
  70.     
  71.     /**
  72.      * Executed when the user clicks at click to buy button
  73.      */
  74.     public function onBuyClick$param )
  75.     {
  76.         $cart_items TSession::getValue('cart_items');
  77.         if (isset($cart_items$param['product_id'] ]))
  78.         {
  79.             $cart_items$param['product_id'] ] ++;
  80.         }
  81.         else
  82.         {
  83.             $cart_items$param['product_id'] ] = 1;
  84.         }
  85.         
  86.         TSession::setValue('cart_items'$cart_items);
  87.         
  88.         $this->enableManagement();
  89.         
  90.         $posAction = new TAction( array('CartManagementView''onReload') );
  91.         new TMessage('info''You have chosen the product: ' $param['product_id'], $posAction);
  92.     }
  93.      public function onEdit$param )
  94.     {
  95.         //para teste
  96.         new TMessage('info','onEdit');
  97.         $param['key'] = '3';
  98.         TSession::setValue('categoria'$param['key']);
  99.     }   
  100.     /**
  101.      * Fill the html template with objects
  102.      */
  103.     public function onReload$param )
  104.     {
  105.         try
  106.         {
  107.             $limit 6;
  108.             
  109.             // load the products
  110.             TTransaction::open('samples');
  111.             $criteria = new TCriteria;
  112.             $criteria->add(new TFilter('photo_path''<>'''));
  113.             
  114.             
  115.             
  116.             $criteria->setProperties($param); // order, offset
  117.             $criteria->setProperty('limit'$limit);
  118.             if (TSession::getValue('busca_filter1'))
  119.             {
  120.                 $criteria->add(TSession::getValue('busca_filter1'));
  121.                 //TSession::setValue('busca_filter1', NULL);
  122.                 //TSession::setValue('busca', '');
  123.                 //new TMessage('info','157');
  124.             }
  125.             $products Product::getObjects($criteria);
  126.             
  127.             $criteria->resetProperties(); // reset the criteria for record count
  128.             $countProduct::countObjects($criteria);
  129.             
  130.             TTransaction::close();
  131.             
  132.             $replace_detail = array();
  133.             if ($products)
  134.             {
  135.                 // iterate products
  136.                 foreach ($products as $product)
  137.                 {
  138.                     $replace_detail[] = $product->toArray(); // array of replacements
  139.                 }
  140.             }
  141.             
  142.             // enable products section as repeatable
  143.             $this->html->enableSection('products'$replace_detailTRUE);
  144.             
  145.             $this->pageNavigation->setCount($count); // count of records
  146.             $this->pageNavigation->setProperties($param); // order, page
  147.             $this->pageNavigation->setLimit($limit); // limit
  148.         }
  149.         catch (Exception $e)
  150.         {
  151.             new TMessage('error'$e->getMessage());
  152.         }
  153.     }
  154.     
  155.     public function show()
  156.     {
  157.         $this->onReloadfunc_get_arg(0) );
  158.         parent::show();
  159.     }
  160.     function onSearch()
  161.     {
  162.         $data $this->form->getData(); // optional parameter: active record class
  163.         if ((isset($data->busca) AND ($data->busca))){
  164.             $filter = new TFilter('description''like'"%{$data->busca}%");
  165.             TSession::setValue('busca_filter1'$filter);
  166.             TSession::setValue('busca'$data->busca);
  167.             $this->form->setData($data);
  168.         }else{
  169.                     TSession::setValue('busca_filter1'NULL);
  170.                     TSession::setValue('busca''');            
  171.         }
  172.         $param=array();
  173.         $param['offset']    =0;
  174.         $param['first_page']=1;
  175.         $this->onReload($param);
  176.     }    
  177. }
LJ

Ufa, Resolvido, fui substituindo os códigos e acabou funcionando.
quanto a imagem que aparecia 2 x , peguei um código meu antigo e deu certo.
  1. <?php
  2. /**
  3.  * Product catalog
  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 FrontCategoria extends TPage
  13. {
  14.     private $html;
  15.     private $pageNavigation;
  16.     
  17.     private $form;
  18.        
  19.     /**
  20.      * Constructor method
  21.      */
  22.     public function __construct()
  23.     {
  24.         parent::__construct();
  25.         
  26.         // load the styles
  27.         TPage::include_css('app/resources/css/bootstrap.min.css');
  28.         TPage::include_js('app/resources/js/jquery-2.2.0.min.js');
  29.         TPage::include_js('app/resources/js/bootstrap.min.js');
  30.         TPage::include_css('app/resources/catalog.css');
  31.  
  32.         $this->form = new TQuickForm;
  33.         $this->form->class 'tform';
  34.         $this->form->setFormTitle('Evento');
  35.         
  36.         // create the form fields
  37.         $nome        = new TEntry('nome');
  38.         $dataevento  = new TDate('dataevento');
  39.         $busca       = new TEntry('busca');
  40.         
  41.         
  42.         $nome->setEditableFALSE ); 
  43.         $dataevento->setEditableFALSE );     
  44.         $this->frame = new TElement('div');
  45.         $this->frame->id 'photo_frame';
  46.         $this->frame->style 'width:150px;height:auto;min-height:150px;border:1px solid gray;padding:4px;';
  47.         $row $this->form->addRow();
  48.         $row->addCell('');
  49.         $row->addCell($this->frame);
  50.         //$this->imagem = new TImage('imagem');
  51.         //$this->frame->add($this->imagem);    
  52.         
  53.         $this->imgFoto = new TElement('img');
  54.         $this->imgFoto->src "";
  55.         $this->frame->add($this->imgFoto); 
  56.         
  57.         $this->form->addQuickField('Nome'$nome,  200);
  58.         $this->form->addQuickField('Data'$dataevento,  100);
  59.         $this->form->addQuickField('Número de Peito'$busca100);        
  60.         // define the form action 
  61.         $this->form->addQuickAction('Buscar', new TAction(array($this'onSearch')), 'fa:check-circle-o green');            
  62.  
  63.         // create the HTML Renderer
  64.         $this->html = new THtmlRenderer('app/resources/categoria.html');
  65.         // define replacements for the main section
  66.         $replace = array();
  67.         
  68.         // replace the main section variables
  69.         $this->html->enableSection('main'$replace);
  70.         
  71.         $this->enableManagement();
  72.         
  73.         // creates the page navigation
  74.         $this->pageNavigation = new TPageNavigation;
  75.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  76.         
  77.         // wrap the page content using vertical box
  78.         $vbox = new TVBox;
  79.         $vbox->add($this->form);
  80.         //$vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  81.         $vbox->add($this->html);
  82.         $vbox->add($this->pageNavigation);
  83.         parent::add($vbox);
  84.     }
  85.     
  86.     /**
  87.      * Enable or not the 'manage' section
  88.      */
  89.     public function enableManagement()
  90.     {
  91.         if (is_array(TSession::getValue('cart_items')) AND count(TSession::getValue('cart_items')) > 0)
  92.         {
  93.             $this->html->enableSection('manage');
  94.         }
  95.     }
  96.     
  97.     /**
  98.      * Executed when the user clicks at click to buy button
  99.      */
  100.     public function onBuyClick$param )
  101.     {
  102.         $cart_items TSession::getValue('cart_items');
  103.         if (isset($cart_items$param['product_id'] ]))
  104.         {
  105.             $cart_items$param['product_id'] ] ++;
  106.         }
  107.         else
  108.         {
  109.             $cart_items$param['product_id'] ] = 1;
  110.         }
  111.         
  112.         TSession::setValue('cart_items'$cart_items);
  113.         
  114.         $this->enableManagement();
  115.         
  116.         $posAction = new TAction( array('CartManagementView''onReload') );
  117.         new TMessage('info''You have chosen the product: ' $param['product_id'], $posAction);
  118.     }
  119.      public function onEdit$param )
  120.     {
  121.         TSession::setValue('categoria'$param['key']);
  122.     }   
  123.     /**
  124.      * Fill the html template with objects
  125.      */
  126.     public function onReload$param )
  127.     {
  128.         try
  129.         {
  130.             $limit 16;
  131.             
  132.             // load the products
  133.             TTransaction::open('ecommerce');
  134.             $cat TSession::getValue('categoria');
  135.             // atualiza o form
  136.             $categoria= new Categoria($cat);
  137.             $categoria->dataevento TDate::date2br($categoria->dataevento);
  138.             $this->imgFoto->src $categoria->imagem;                        
  139.             $this->form->setData($categoria);            
  140.             
  141.             
  142.             $criteria = new TCriteria;
  143.             $criteria->add(new TFilter('categoria_id','=',$cat));
  144.             $criteria->setProperties($param); // order, offset
  145.             $criteria->setProperty('limit'$limit);
  146.             if (TSession::getValue('busca_filter1'))
  147.             {
  148.                 $criteria->add(TSession::getValue('busca_filter1'));
  149.             }
  150.             $products Produto::getObjects($criteria);
  151.             
  152.             $criteria->resetProperties(); // reset the criteria for record count
  153.             $countProduto::countObjects($criteria);
  154.              $replace = array();
  155.             if($products)
  156.             {
  157.             $i=0;
  158.             foreach ($products as $produto)
  159.             {
  160.             $replace['produto'][$i]['id']=    $produto->id;    
  161.             $replace['produto'][$i]['imagem']= $produto->imagem;    
  162.             //programar nome da corrida - ok
  163.             $replace['produto'][$i]['evento']=  $categoria->nome;
  164.             $precos $produto->getPrecos();
  165.             $x=0
  166.             foreach ($precos as $preco)
  167.                 {
  168.                     $replace['produto'][$i]['preco'][$x]['id']=    $produto->id;    
  169.                     $replace['produto'][$i]['preco'][$x]['preco_id']=$preco->id;
  170.                     $replace['produto'][$i]['preco'][$x]['valor']=' R$ '.$preco->preco.'  Tamanho: '.$preco->tamanho;
  171.                     $x++;
  172.                 }            
  173.             $i++;            
  174.             }
  175.             TTransaction::close();    
  176.             }  
  177.             
  178.             $this->html->enableSection('main'$replace);
  179.             
  180.             $this->pageNavigation->setCount($count); // count of records
  181.             $this->pageNavigation->setProperties($param); // order, page
  182.             $this->pageNavigation->setLimit($limit); // limit
  183.         }
  184.         catch (Exception $e)
  185.         {
  186.             new TMessage('error'$e->getMessage());
  187.         }
  188.     }
  189.     
  190.     public function show()
  191.     {
  192.         $this->onReloadfunc_get_arg(0) );
  193.         parent::show();
  194.     }
  195.     function onSearch()
  196.     {
  197.         $data $this->form->getData(); // optional parameter:
  198.         if ((isset($data->busca) AND ($data->busca))){
  199.             $filter = new TFilter('busca''like'"%{$data->busca}%");
  200.             TSession::setValue('busca_filter1'$filter);
  201.             TSession::setValue('busca'$data->busca);
  202.             $this->form->setData($data);
  203.         }else{
  204.                     TSession::setValue('busca_filter1'NULL);
  205.                     TSession::setValue('busca''');            
  206.         }
  207.         $param=array();
  208.         $param['offset']    =0;
  209.         $param['first_page']=1;
  210.         $this->onReload($param);
  211.     }    
  212. }
  213. ?>