Problem with Filter, CListView and Pagination

Hi!

On my index-page I have a search-field.




echo CHtml::form(CHtml::normalizeUrl(array('betriebsstelle/search')));

echo CHtml::DropDownList("searchid", " - Suche - ",array(1=>'Hostname',2=>'Betriebsstellenname',3=>'Strasse',4=>'VenedigID',5=>'Auftragsnummer'));

echo CHtml::textField("searchField");

echo CHtml::submitButton('Suchen');

echo CHtml::endForm();



This search-request is handled by the function actionSearch().




	 public function actionSearch() {

	 

	 if(isset($_POST['searchid']) && isset($_POST['searchField'])){

		switch ($_POST['searchid']) {

		//Hostname

		case 1:

			$criteria=new CDbCriteria;

			$criteria->alias = 'Betriebsstelle';

			$criteria->join='INNER JOIN CPE on CPE.Betriebsstelle_idBetriebsstellen=Betriebsstelle.idBetriebsstellen';

			$criteria->condition='CPE.CPEName LIKE "%'.$_POST['searchField'].'%"';

			$criteria->group='Betriebsstelle.idBetriebsstellen';

			

			$dataProvider=new CActiveDataProvider('Betriebsstelle', array('criteria'=>$criteria));

			break;

		//BS Name

                ...

default:

			$dataProvider=new CActiveDataProvider('Betriebsstelle');

		}

	}else{

		$dataProvider=new CActiveDataProvider('Betriebsstelle');

	}

	$this->render('index',array(

		'dataProvider'=>$dataProvider

	));

	}



The defaul CListView displays the result:




<?php $this->widget('zii.widgets.CListView', array(

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

)); ?>



The first page is shown correctly. If I want to go to page 2 CListView shows page 2 of all items and not of my search-request (filter).

How can I solve this Probleme?

Try to do somethinf like this:

on your index action in controller you should write:




...

$model= new Betriebsstelle('search');

...

$this->render('index', array('model'=>$model));



Then, in CListView:




<?php $this->widget('zii.widgets.CListView', array(

        'dataProvider'=>$model->search,

        'itemView'=>'_view',

)); ?>



You can see it in standard actionAdmin() and view ‘admin.php’.

Generally speaking, for your purposes would be better spent CGridView, not CListView.

Hi Layne,

thanks for your answer!

But I think it will not solve my problem.

The search with the CActiveDataProvider and the CDbCriteria works fine.

The first page that is displayed after the search the result is as designated.

But the fields of my search-form aren’t stored in the pagination. So, if I click on page 2 of my search result the CActiveDataProvider is displayed without any criteria (the default in the switch case)

I solved the problem by using GET instead of POST in the form.


echo CHtml::form(CHtml::normalizeUrl(array('betriebsstelle/search')),'get');

i’m trying to find a way using POST, i don’t like the url messed up with GET parameters