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

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