Answer the question
In order to leave comments, you need to log in
Pagination when searching for Yii framework, how to implement it correctly?
Good afternoon! Please tell me how to do it right. Thanks in advance.
The essence of the problem is that when you change the search criteria, everything is fine, it displays the necessary records and the number of pages in the pagination corresponds to them, but if you start to navigate through the post, navigation, it reloads the page and spits out all the records again.
A piece of search, on click, collects data from the form and generates a request.
I send to action.
public function actionIndex()
{
$model = new ApartmentsItem('search');
/* Данные пришедшие с формы ajax`om , если их нет, выводит все записи */
$criteria = $model->CSearch( (object)$_POST['search'] );
$count = ApartmentsItem::model()->count($criteria);
$pagination = new CPagination($count);
$pagination->pageSize = 3;
$pagination->applyLimit($criteria);
$model = ApartmentsItem::model()->findAll($criteria);
$this->render('index', array(
'model' => $model,
'pagination' => $pagination
));
}
public function CSearch($data)
{
$criteria=new CDbCriteria;
$criteria->compare('city', $data->city);
$criteria->compare('price',$data->price);
return $criteria;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question