我怎样才能实现这些目标?
public function actionIndex()
{
$criteria = new CDbCriteria();
$criteria->order = 'id DESC';
$criteria->condition = 'title LIKE OR description LIKE';
$item_count = OfferEvents::model()->count($criteria);
$page_size =5;
$pages =new CPagination($item_count);
$pages->setPageSize($page_size);
// simulate the effect of LIMIT in a sql query
$end =($pages->offset+$pages->limit <= $item_count ? $pages->offset+$pages->limit : $item_count);
$sample =range($pages->offset+1, $end);
$this->render('index', array(
'item_count'=>$item_count,
'page_size'=>$page_size,
'items_count'=>$item_count,
'pages'=>$pages,
'sample'=>$sample,
));
}
在我看来我添加了这个
<div class="page" style="margin-left:500px;">
<?php
$this->widget('CLinkPager', array(
'currentPage'=>$pages->getCurrentPage(),
'itemCount'=>$item_count,
'pageSize'=>$page_size,
'maxButtonCount'=>6,
'nextPageLabel'=>'Next >',
'header'=>'',
));
?>
</div>
答案 0 :(得分:0)
$criteria->condition = 'title LIKE :title OR description LIKE :description'; // step 1
$criteria->params = array(':title' => $title, ':description' => $description); // step 2
这里在
:title
和:description
。params
的{{1}}方法,该方法包含一个关联数组,其CDbCriteria
是SQL中的参数。分页:
keys