working with yii-1.1.6-2688, MySQL: 5.1.37
I have Unconsistancy between pagination/item numbers and request results/item numbers in CListView.
Is this a bug or am I missing something ?
I am making a big request to search by proximity. The request works perfectly and returns for this example 2 items. However the pager still shows pagination among 26 items (the total number of items of the testing-table).
My relations are:
return array(
'owner'=>array(self::BELONGS_TO, 'Users', 'owner_id'),
'account'=>array(self::BELONGS_TO, 'Accounts', 'owner_id'),
'category'=>array(self::BELONGS_TO, 'Categories', 'category_id'),
'picture'=>array(self::HAS_MANY, 'Pictures', 'ad_id'),
'location'=>array(self::HAS_ONE,'Locations','ad_id'),
);
See the image:1010
This is the big request: I tried it in pure SQL too, it really returns the 2 objects
SELECT `t`.`id` AS `t0_c0`, `t`.`code` AS `t0_c1`, `t`.`from` AS `t0_c2`, `t`.`to` AS `t0_c3`, `t`.`cltime` AS `t0_c4`, `t`.`owner_id` AS `t0_c5`, `t`.`pubname` AS `t0_c6`, `t`.`pubmail` AS `t0_c7`, `t`.`pubphone` AS `t0_c8`, `t`.`category_id` AS `t0_c9`, `t`.`subdomain` AS `t0_c10`, `t`.`offer_type` AS `t0_c11`, `t`.`subject` AS `t0_c12`, `t`.`content` AS `t0_c13`, `t`.`price` AS `t0_c14`, `t`.`free` AS `t0_c15`, `t`.`slug` AS `t0_c16`, `t`.`confirmkey` AS `t0_c17`, `t`.`published` AS `t0_c18`, `t`.`archived` AS `t0_c19`, `t`.`created` AS `t0_c20`, `t`.`updated` AS `t0_c21`, `t`.`viewed` AS `t0_c22`,
`owner`.`id` AS `t1_c0`, `owner`.`username` AS `t1_c1`, `owner`.`password` AS `t1_c2`, `owner`.`email` AS `t1_c3`, `owner`.`phone` AS `t1_c4`, `owner`.`activkey` AS `t1_c5`, `owner`.`createtime` AS `t1_c6`, `owner`.`lastvisit` AS `t1_c7`, `owner`.`superuser` AS `t1_c8`, `owner`.`status` AS `t1_c9`, `owner`.`avatar` AS `t1_c10`, `owner`.`is_oauth` AS `t1_c11`, `owner`.`token` AS `t1_c12`,
`category`.`id` AS `t2_c0`, `category`.`subdomain` AS `t2_c1`, `category`.`parent_id` AS `t2_c2`, `category`.`name` AS `t2_c3`, `category`.`slug` AS `t2_c4`, `category`.`special` AS `t2_c5`, `category`.`sequence` AS `t2_c6`, `category`.`disabled` AS `t2_c7`, `category`.`count_ads` AS `t2_c8`,
`account`.`id` AS `t3_c0`, `account`.`user_id` AS `t3_c1`, `account`.`professionnal` AS `t3_c2`, `account`.`created` AS `t3_c3`, `account`.`updated` AS `t3_c4`,
`picture`.`id` AS `t4_c0`, `picture`.`ad_id` AS `t4_c1`, `picture`.`file_code` AS `t4_c2`, `picture`.`sequence` AS `t4_c3`, `picture`.`visible` AS `t4_c4`, `picture`.`title` AS `t4_c5`, `picture`.`type` AS `t4_c6`, `picture`.`size` AS `t4_c7`, `picture`.`widthxheight` AS `t4_c8`, `picture`.`created` AS `t4_c9`, `picture`.`updated` AS `t4_c10`, `location`.`lat` AS `t5_c9`, `location`.`lng` AS `t5_c10`, (calculatedist(:lat,:lng)) AS distance, `location`.`id` AS `t5_c0` FROM `cl_ads` `t` LEFT OUTER JOIN `cl_users` `owner` ON (`t`.`owner_id`=`owner`.`id`)
LEFT OUTER JOIN `cl_categories` `category` ON (`t`.`category_id`=`category`.`id`)
LEFT OUTER JOIN `cl_accounts` `account` ON (`t`.`owner_id`=`account`.`id`)
LEFT OUTER JOIN `cl_pictures` `picture` ON (`picture`.`ad_id`=`t`.`id`)
LEFT OUTER JOIN `cl_locations` `location` ON (`location`.`ad_id`=`t`.`id`)
WHERE (t.archived=0 AND t.subdomain="france") HAVING (distance<=1.609344)
ORDER BY t.created DESC, t.created DESC, distance ASC LIMIT 5
This is how I prepare the Sort,Pager:
$sort = new CSort('Ads');
$sort->defaultOrder='t.created DESC';
$sort->attributes = array(
'created'=>array(
'asc'=>'t.created ASC',
'desc'=>'t.created DESC',
),
'price'=>array(
'asc'=>'t.price ASC',
'desc'=>'t.price DESC',
),
'viewed'=>array(
'asc'=>'t.viewed ASC',
'desc'=>'t.viewed DESC',
),
);
$sort->applyOrder($criteria);
$count=count(Ads::model()->with($withOption)->findAll($criteria));
$pages=new CPagination($count);
$pages->pageSize=self::PAGE_SIZE;// this is five items
$pages->applyLimit($criteria);
$pages->setItemCount($count); //$pages->getPageCount(); is ok too
$criteria->limit =self::CRITERIA_LIMIT;
$dataProvider=new CActiveDataProvider('Ads', array(
'criteria' => $criteria,
'pagination'=>$pages,
'sort'=>$sort,
)
);
And now CListview Call where I added the pager test which shouldn’t be necessary at pagination has already been passed above into dataProvider.
//TEST
$pager=array();
$pager['pages']=$dataProvider->getPagination();//$pager['pages']->getPageCount()
echo '<br>( $pager["pages"]->itemCount returned: '.$pager['pages']->itemCount.')';
$this->widget('zii.widgets.CListView', array(
'ajaxUpdate'=>'cl',
'dataProvider'=>$dataProvider,
'id'=>'cl',
'itemsCssClass'=>'itemsCssClass',
'itemView'=>'_itemView',
'template' => '{summary}{sorter}<br><br> {items} <div style="clear:both"></div>{pager}',
'enableSorting'=>true,
'enablePagination'=>true,
'sortableAttributes'=>$sortable,
'cssFile'=>'cssFile',
'pager'=>$pager,
));