A
A
Alexanqp2015-05-11 12:13:17
Yii
Alexanqp, 2015-05-11 12:13:17

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.
3TBmnXSYB3Q.jpg
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
        ));
}

criteria formation method
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

1 answer(s)
G
George, 2015-05-11
@Alexanqp

Use GET to filter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question