Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework] Zmiana przesyłania z POST na GET
Ravik
post
Post #1





Grupa: Zarejestrowani
Postów: 95
Pomógł: 3
Dołączył: 8.05.2009

Ostrzeżenie: (0%)
-----


Witam,

Chciałbym zapytać jak w tym kawałku kodu zmienić metodę przesyłania z POST na GET. Być może dla niektórych jest to banał, niestety ja nie mam pojęcia o zend framework (szukałem artykułów z tym związanych, jednak moje działania nie przyniosły skutku).

Będę zobowiązany za pomoc.

Funkcja odpowiadająca za wyszkuwanie:

  1. function searchAction() {
  2.  
  3.  
  4.  
  5. // get db adapter and session data
  6.  
  7. $db = Zend_Registry::get('db');
  8.  
  9. $db->setFetchMode(Zend_Db::FETCH_OBJ);
  10.  
  11. $search = new Zend_Session_Namespace('search');
  12.  
  13. $settings = new SettingsTable;
  14.  
  15. $pageLimit = $settings->fetchRow('title = "pageLimit"');
  16.  
  17.  
  18.  
  19. // if isset post data then set new search variables
  20.  
  21. if($this->_request->isPost()) {
  22.  
  23.  
  24.  
  25. $search->where = NULL;
  26.  
  27.  
  28.  
  29. // set where
  30.  
  31. foreach($this->_request->getPost() as $name => $value)
  32.  
  33. $post[$name] = $value;
  34.  
  35. if(!empty($post['advertisementType']))
  36.  
  37. $search->where .= ('(advertisements.advertisementType = '.intval($post['advertisementType'])).') AND ';
  38.  
  39. if(!empty($post['propertyType']))
  40.  
  41. $search->where .= ('(advertisements.propertyType = '.intval($post['propertyType'])).') AND ';
  42.  
  43. if(!empty($post['province']))
  44.  
  45. $search->where .= ('(advertisements.province = '.intval($post['province'])).') AND ';
  46.  
  47. if(!empty($post['city']))
  48.  
  49. $search->where .= ('(advertisements.city LIKE "%'.$post['city'].'%"').') AND ';
  50.  
  51. if(!empty($post['priceFrom']))
  52.  
  53. $search->where .= ('(advertisements.price > '.floatval($post['priceFrom'])).') AND ';
  54.  
  55. if(!empty($post['priceFor']))
  56.  
  57. $search->where .= ('(advertisements.price < '.floatval($post['priceFor'])).') AND ';
  58.  
  59. if(!empty($post['areaSizeFrom']))
  60.  
  61. $search->where .= ('(advertisements.areaSize > '.intval($post['areaSizeFrom'])).') AND ';
  62.  
  63. if(!empty($post['areaSizeFor']))
  64.  
  65. $search->where .= ('(advertisements.areaSize < '.intval($post['areaSizeFor'])).') AND ';
  66.  
  67. if(!empty($post['keyword']))
  68.  
  69. $search->where .= ('(advertisements.description LIKE "%'.$post['keyword'].'%"').') AND ';
  70.  
  71. $search->where = substr($search->where, 0, (strlen($search->where)-4));
  72.  
  73.  
  74.  
  75. }
  76.  
  77.  
  78.  
  79. if(!empty($search->where) && $this->_request->getParam('page') >= 1) {
  80.  
  81.  
  82.  
  83. // get count finded advertisements
  84.  
  85. $advertisements = new AdvertisementsTable;
  86.  
  87. $select = $advertisements->select();
  88.  
  89. $select->from($advertisements, 'count(id) as count')
  90.  
  91. ->where($search->where);
  92.  
  93. $row = $advertisements->fetchRow($select);
  94.  
  95. $this->view->search = true;
  96.  
  97.  
  98.  
  99. if($row->count > 0) {
  100.  
  101.  
  102.  
  103. // create final query
  104.  
  105. $select = $db->select();
  106.  
  107. $select->from('advertisements', array('id', 'areaSize', 'price', 'description', 'city', 'announceDate', 'promo'))
  108.  
  109. ->joinInner('propertyTypes', 'propertyTypes.id = advertisements.propertyType', 'type as propertyType')
  110.  
  111. ->joinInner('advertisementTypes', 'advertisementTypes.id = advertisements.advertisementType', 'type as advertisementType')
  112.  
  113. ->joinInner('provinces', 'provinces.id = advertisements.province', 'province')
  114.  
  115. ->joinLeft('images', 'images.advertisementId = advertisements.id', 'image')
  116.  
  117. ->where($search->where)
  118.  
  119. ->where('dayCounter > 0')
  120.  
  121. ->group('id')
  122.  
  123. ->order(array('promo DESC', 'announceDate DESC'))
  124.  
  125. ->limit($pageLimit->value, ($this->_request->getParam('page')-1)*$pageLimit->value);
  126.  
  127.  
  128.  
  129. $result = $db->query($select);
  130.  
  131. $this->view->advertisements = $result->fetchAll();
  132.  
  133.  
  134.  
  135. // set pages parameters
  136.  
  137. $this->view->pagesLink = 'adv/search/';
  138.  
  139. $this->view->pagesCount = $row->count;
  140.  
  141. $this->view->pagesLimit = $pageLimit->value;
  142.  
  143. $this->view->pagesCurrent = $this->_request->getParam('page');
  144.  
  145.  
  146.  
  147. }
  148.  
  149.  
  150.  
  151. }
  152.  
  153.  
  154.  
  155. }


HTML+PHP (wiem, żeby zmienić <form action="get">)

  1. <table style="width:370px;">
  2.  
  3. <form method="post" action="adv/search/1.html">
  4.  
  5. <fieldset>
  6.  
  7. <tr>
  8.  
  9. <td>Rodzaj ogłoszenia: </td>
  10.  
  11. <td>
  12.  
  13. <select class="sinput" name="advertisementType">
  14.  
  15. <option value="0">- wszystkie ogłoszenia -</option>
  16.  
  17. <?php
  18.  
  19. foreach($this->AdvertisementTypes as $AdvertisementType)
  20.  
  21. echo '<option value="'.$AdvertisementType->id.'">'.$AdvertisementType->type.'</option>';
  22.  
  23. ?>
  24.  
  25. </select>
  26.  
  27. </td>
  28.  
  29. </tr>
  30.  
  31.  
  32.  
  33. <tr>
  34.  
  35. <td>Typ nieruchomości: </td>
  36.  
  37. <td>
  38.  
  39. <select class="sinput" name="propertyType">
  40.  
  41. <option value="0">- wszystkie typy -</option>
  42.  
  43. <?php
  44.  
  45. foreach($this->PropertyTypes as $PropertyType)
  46.  
  47. echo '<option value="'.$PropertyType->id.'">'.$PropertyType->type.'</option>';
  48.  
  49. ?>
  50.  
  51. </select>
  52.  
  53. </td>
  54.  
  55. </tr>
  56.  
  57.  
  58.  
  59. <tr>
  60.  
  61. <td>Województwo: </td>
  62.  
  63. <td>
  64.  
  65. <select name="province" class="sinput">
  66.  
  67. <option selected="selected" value="0">- dowolne województwo -</option>
  68.  
  69. <?php
  70.  
  71. foreach($this->provinces as $province)
  72.  
  73. echo '<option value="'.$province->id.'">'.$province->province.'</option>';
  74.  
  75. ?>
  76.  
  77. </select>
  78.  
  79. </td>
  80.  
  81. </tr>
  82.  
  83.  
  84.  
  85. <tr>
  86.  
  87. <td>Miasto:</td>
  88.  
  89. <td><input name="city" class="sinput"/></td>
  90.  
  91. </tr>
  92.  
  93.  
  94.  
  95. <tr>
  96.  
  97. <td>Cena (PLN):</td>
  98.  
  99. <td>
  100.  
  101. od <input name="priceFrom" class="sinput2"/> do <input name="priceFor" class="sinput2"/>
  102.  
  103. </td>
  104.  
  105. </tr>
  106.  
  107.  
  108.  
  109. <tr>
  110.  
  111. <td>Powierzchnia (m<sup><small>2</small></sup>):</td>
  112.  
  113. <td>
  114.  
  115. od <input name="areaSizeFrom" class="sinput2"/> do <input name="areaSizeFor" class="sinput2"/>
  116.  
  117. </td>
  118.  
  119. </tr>
  120.  
  121.  
  122.  
  123. <tr>
  124.  
  125. <td>Słowo kluczowe:</td>
  126.  
  127. <td>
  128.  
  129. <input name="keyword" class="sinput"/>
  130.  
  131. </td>
  132.  
  133. </tr>
  134.  
  135.  
  136.  
  137. <tr>
  138.  
  139. <td></td>
  140.  
  141. <td>
  142.  
  143. <input type="image" style="margin-top:5px;margin-right:10px;" src="public/images/search.gif" onclick="this.form.submit()" value="Szukaj" />
  144.  
  145. </td>
  146.  
  147. </tr>
  148.  
  149.  
  150.  
  151.  
  152.  
  153. </fieldset>
  154.  
  155. </form>
  156.  
  157. </table>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.12.2025 - 18:43