I have a simple search
public function search() {
$criteria=new CDbCriteria;
$criteria->with = array('agent');
$criteria->compare('full_name',$this->full_name,true);
if ($this->gender_id != "") {
$criteria->compare('gender_id',$this->gender_id);
}
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>30,
),
));
}
But I don’t like that the search parameters appear in the address bar when you use the get method to search. I’ve changed my search widget to use the post method instead:
$form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'post',
));
But now when I hit the search button the page just refreshes instead of showing the search results, I assume I’m missing something here…
In your actionAdmin function of the controller replace $_GET by $_POST…
replace $_GET in above lines by $_POST like:
On a side note on search it is always advised to use GET instead of POST, the basic rule i use is whenever some data needs to be submitted it should be POST, whenever some data needs to be fetched it should be GET..
Update:
The main reasons I can think of i would use GET for search
1) In searches user needs the functionality to back to previous filter, which if used as get url params, is straight forward.
2) If the filter params are in url, its extremely easy to share results after certain filters..Imagine you want to share some results with a friend, would you give him instructions to filter step by step (In case of POST), or give a direct url(GET)
3) Its very easy to change params from url, imagine currently you are visiting 2nd page, but on page while displaying filters only links to next 5 pages are displayed, but you want to jump to straight 15th page results..
There will be many more advantages, I can think of these at the moment..