O
O
Oleg Lysenko2016-05-17 16:58:17
Yii
Oleg Lysenko, 2016-05-17 16:58:17

Who can help with Yii pagination?

Hello, there is a problem with the ListView widget and pagination. The bottom line is that there is a display of goods on the site and for some reason the number of pagination pages is formed incorrectly, namely exactly 50% of extra pages that are empty. Has anyone experienced this, please help.
view

$this->widget('bootstrap.widgets.BsListView', array(
    'dataProvider'=>$model->search(),
              'ajaxUpdate' => true,
    'itemView'=>'application.views.shopProducts._view',
    'enablePagination' => true,
                'id'=>$name,
    'itemsCssClass'=>'items table table-striped table-condensed',
    'emptyText'=>'<i> Нет продуктов.</i>',
      'template' => '<div class="row">{items}</div>{pager}'

controller
public function actionSearch() {

                $model = new ShopProducts('search');
                $model->unsetAttributes();  // clear any default values
                $model->main_category = ShopCategory::model()->findByAttributes(array('alias'=>$_GET['alias']));
                $model->main_category = $model->main_category->id;
                if(!isset($_GET['brand']) && is_array($_GET['brand']))
                        $cats = ShopCategory::getAllSubCategories($model->main_category);


                if (isset($_GET['ShopProducts']))
                        $model->attributes = $_GET['ShopProducts'];

                         if(!isset($_GET['brand']) && is_array($_GET['brand']))$model->withInCategory($cats);
                        $model->withPrice()->withMainPhoto();


                if(isset($_GET['brand']) && is_array($_GET['brand'])){

                        $shopCat = array();


                        foreach ($_GET['brand'] as $item) {

                                $v = ShopCategory::getAllSubCategories($item);

                                foreach($v as $k){
                                        $shopCats[] = $k;
                                }
                                $allCats = array_merge($shopCat, $shopCats);
                                $model->withInCategory($allCats);
                        }


                }

                if(isset($_GET['liquid']) && is_array($_GET['liquid'])){

                        $model->liquid = implode(', ', $_GET['liquid']);

                }

                if(isset($_GET['plant']) && is_array($_GET['plant'])){

                        $model->plant = implode(', ', $_GET['plant']);

                }

                if(isset($_GET['capacity_from']) || isset($_GET['capacity_to'])){

                        $model->capacity_from = $_GET['capacity_from'];
                        $model->capacity_to = $_GET['capacity_to'];

                }

                if(isset($_GET['pressure_from']) || isset($_GET['pressure_to'])){

                        $model->pressure_from = $_GET['pressure_from'];
                        $model->pressure_to = $_GET['pressure_to'];

                }

                if(isset($_GET['voltage']) && is_array($_GET['voltage'])){

                        $model->voltage = implode(', ', $_GET['voltage']);

                }

                /*Баки*/

                if(isset($_GET['plant_bak']) && is_array($_GET['plant_bak'])){

                        $model->plant_bak = implode(', ', $_GET['plant_bak']);

                }

                 if(isset($_GET['volume_from']) || isset($_GET['volume_to'])){

                        $model->volume_from = $_GET['volume_from'];
                        $model->volume_to = $_GET['volume_to'];

                }

                /*Насосные станции*/

                if(isset($_GET['deep_from']) || isset($_GET['deep_to'])){

                        $model->deep_from = $_GET['deep_from'];
                        $model->deep_to = $_GET['deep_to'];

                }

                /*Автоматика*/

                if(isset($_GET['tok_from']) || isset($_GET['tok_to'])){

                        $model->tok_from = $_GET['tok_from'];
                        $model->tok_to = $_GET['tok_to'];

                }

                if(isset($_GET['type']) && is_array($_GET['type'])){

                        $model->type = implode(', ', $_GET['type']);

                }

                /*Комплектующие*/

                if(isset($_GET['type_details']) && is_array($_GET['type_details'])){

                        $model->type_details = implode(', ', $_GET['type_details']);

                }

                /*Фильтры для воды*/

                if(isset($_GET['type_filter']) && is_array($_GET['type_filter'])){

                        $model->type_filter = implode(', ', $_GET['type_filter']);

                }

                /*Водоподготовка*/

                if(isset($_GET['type_water']) && is_array($_GET['type_water'])){

                        $model->type_water = implode(', ', $_GET['type_water']);

                }

                if(isset($_GET['water']) && is_array($_GET['water'])){

                        $model->water = implode(', ', $_GET['water']);

                }

                $this->filter = $this->renderPartial('application.views.shopCategory.filter_'.$_GET['alias'],array(
                'model'=>$model),true);

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

Model
protected function beforeFind() {

        parent::beforeFind();

        if(isset($this->price_from) || isset($this->price_to)){
            $criteria = new CDbCriteria;
            $criteria->group = "cms_files.id_obj";
            $criteria->join = 'LEFT JOIN `shop_prices` shpr ON t.`id_price` = shpr.`id`';
            $criteria->condition = "1=1 ".($this->price_from?' AND shpr.price*'.(Yii::app()->controller->currency['value']).'>='.$this->price_from:'').($this->price_to?' AND shpr.price*'.(Yii::app()->controller->currency['value']).'<='.$this->price_to:'');
            $this->getDbCriteria()->mergeWith($criteria);

        }
        ...

public function search()
  {
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    $criteria->compare('prior',$this->prior);
    $criteria->compare('name_ru',$this->name_ru,true);
    $criteria->compare('alias',$this->alias,true);
    $criteria->compare('description',$this->description_ru,true);
    $criteria->compare('long_description',$this->long_description_ru,true);
    $criteria->compare('id_price',$this->id_price);

    $criteria->compare('prod_view',$this->prod_view);

    return new CActiveDataProvider($this, array(
      'criteria'=>$criteria,
                    'pagination'=>array(
        'pageSize'=>12,
    ),
    ));
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question