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:
function searchAction() {
// get db adapter and session data
$db = Zend_Registry::get('db');
$db->setFetchMode(Zend_Db::FETCH_OBJ);
$search = new Zend_Session_Namespace('search');
$settings = new SettingsTable;
$pageLimit = $settings->fetchRow('title = "pageLimit"');
// if isset post data then set new search variables
if($this->_request->isPost()) {
$search->where = NULL;
// set where
foreach($this->_request->getPost() as $name => $value)
$post[$name] = $value;
if(!empty($post['advertisementType']))
$search->where .= ('(advertisements.advertisementType = '.intval($post['advertisementType'])).') AND ';
if(!empty($post['propertyType']))
$search->where .= ('(advertisements.propertyType = '.intval($post['propertyType'])).') AND ';
if(!empty($post['province']))
$search->where .= ('(advertisements.province = '.intval($post['province'])).') AND ';
if(!empty($post['city']))
$search->where .= ('(advertisements.city LIKE "%'.$post['city'].'%"').') AND ';
if(!empty($post['priceFrom']))
$search->where .= ('(advertisements.price > '.floatval($post['priceFrom'])).') AND ';
if(!empty($post['priceFor']))
$search->where .= ('(advertisements.price < '.floatval($post['priceFor'])).') AND ';
if(!empty($post['areaSizeFrom']))
$search->where .= ('(advertisements.areaSize > '.intval($post['areaSizeFrom'])).') AND ';
if(!empty($post['areaSizeFor']))
$search->where .= ('(advertisements.areaSize < '.intval($post['areaSizeFor'])).') AND ';
if(!empty($post['keyword']))
$search->where .= ('(advertisements.description LIKE "%'.$post['keyword'].'%"').') AND ';
$search->where = substr($search->where, 0
, (strlen($search->where)-4
));
}
if(!empty($search->where) && $this->_request
->getParam('page') >= 1) {
// get count finded advertisements
$advertisements = new AdvertisementsTable;
$select = $advertisements->select();
$select->from($advertisements, 'count(id) as count')
->where($search->where);
$row = $advertisements->fetchRow($select);
$this->view->search = true;
if($row->count > 0) {
// create final query
$select = $db->select();
$select->from('advertisements', array('id', 'areaSize', 'price', 'description', 'city', 'announceDate', 'promo'))
->joinInner('propertyTypes', 'propertyTypes.id = advertisements.propertyType', 'type as propertyType')
->joinInner('advertisementTypes', 'advertisementTypes.id = advertisements.advertisementType', 'type as advertisementType')
->joinInner('provinces', 'provinces.id = advertisements.province', 'province')
->joinLeft('images', 'images.advertisementId = advertisements.id', 'image')
->where($search->where)
->where('dayCounter > 0')
->group('id')
->order(array('promo DESC', 'announceDate DESC'))
->limit($pageLimit->value, ($this->_request->getParam('page')-1)*$pageLimit->value);
$result = $db->query($select);
$this->view->advertisements = $result->fetchAll();
// set pages parameters
$this->view->pagesLink = 'adv/search/';
$this->view->pagesCount = $row->count;
$this->view->pagesLimit = $pageLimit->value;
$this->view->pagesCurrent = $this->_request->getParam('page');
}
}
}
HTML+PHP (wiem, żeby zmienić <form action="get">)
<table style="width:370px;">
<form method="post" action="adv/search/1.html">
<fieldset>
<tr>
<td>Rodzaj ogłoszenia: </td>
<td>
<select class="sinput" name="advertisementType">
<option value="0">- wszystkie ogłoszenia -</option>
<?php
foreach($this->AdvertisementTypes as $AdvertisementType)
echo '<option value="'.$AdvertisementType->id.'">'.$AdvertisementType->type.'</option>';
?>
</select>
</td>
</tr>
<tr>
<td>Typ nieruchomości: </td>
<td>
<select class="sinput" name="propertyType">
<option value="0">- wszystkie typy -</option>
<?php
foreach($this->PropertyTypes as $PropertyType)
echo '<option value="'.$PropertyType->id.'">'.$PropertyType->type.'</option>';
?>
</select>
</td>
</tr>
<tr>
<td>Województwo: </td>
<td>
<select name="province" class="sinput">
<option selected="selected" value="0">- dowolne województwo -</option>
<?php
foreach($this->provinces as $province)
echo '<option value="'.$province->id.'">'.$province->province.'</option>';
?>
</select>
</td>
</tr>
<tr>
<td>Miasto:</td>
<td><input name="city" class="sinput"/></td>
</tr>
<tr>
<td>Cena (PLN):</td>
<td>
od <input name="priceFrom" class="sinput2"/> do <input name="priceFor" class="sinput2"/>
</td>
</tr>
<tr>
<td>Powierzchnia (m<sup><small>2</small></sup>):</td>
<td>
od <input name="areaSizeFrom" class="sinput2"/> do <input name="areaSizeFor" class="sinput2"/>
</td>
</tr>
<tr>
<td>Słowo kluczowe:</td>
<td>
<input name="keyword" class="sinput"/>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="image" style="margin-top:5px;margin-right:10px;" src="public/images/search.gif" onclick="this.form.submit()" value="Szukaj" />
</td>
</tr>
</fieldset>
</form>
</table>