In this case, how the right way to count pages?
<?php $keywords=explode(" ",$_GET['q']); foreach($keywords as $keyword) { $sql="SELECT * FROM `content` WHERE `fulltext` LIKE '%$keyword%'"; $searchList=content::model()->findAllBySql($sql); $sqt="SELECT count(id) FROM `content` WHERE `fulltext` LIKE '%$keyword%'"; $total=content::model()->countBySql($sqt); /*$criteria=new CDbCriteria; $criteria->condition='fulltext LIKE %:keyword%'; $criteria->offset=0; $criteria->limit=10; $criteria->params=array(':keyword'=>$keyword);*/ $pages=new CPagination(content::model()->count()); $pages->pageSize=10; $pages->applyLimit($sqt); //approach 1 $pages->applyLimit($criteria); //approach 2 }
Approach 1 making error
Quote
Description
Attempt to assign property of non-object
Source File
C:\www\yii104\framework\web\CPagination.php(158)
00146: else
00147: unset($params[$this->pageVar]);
00148: return $controller->createUrl($this->route,$params);
00149: }
00150:
00151: /**
00152: * Applies LIMIT and OFFSET to the specified query criteria.
00153: * @param CDbCriteria the query criteria that should be applied with the limit
00154: * @since 1.0.1
00155: */
00156: public function applyLimit($criteria)
00157: {
[glow=red,2,300]00158: $criteria->limit=$this->pageSize;[/glow]
00159: $criteria->offset=$this->currentPage*$this->pageSize;
00160: }
00161: }
In approach 2 no error, but give the wrong result, too much number of pages.