我的项目中有一个自定义下拉分页并使用 CListView 显示项目,但它无法正常工作。无论我在下拉列表中选择什么数字或页码,列表的内容都是空的。我可以看到摘要编号已更改并正确显示,但未显示列表。我错过了什么?
下面是模型 - CandidateSearch() 代码:
public function candidateSearch()
{
$criteria = new CDbCriteria;
$criteria->compare('can_id',$this->can_id);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'name ASC',
),
'pagination'=>array(
'pageSize'=> Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']),
),
));
}
下面是控制器代码:
public function actionIndex()
{
if (isset($_GET['pageSize']))
{
Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
unset($_GET['pageSize']);
}
$model = new JbMeetGreet('candidateSearch');
$model->unsetAttributes(); // clear any default values
$model->can_id = Yii::app()->user->id;
$model->created_by = Yii::app()->user->id;
$model->created_by_lvl = Yii::app()->user->user_level;
//search function
if(isset($_POST['JbMeetGreet']))
{
$model->attributes = $_POST['JbMeetGreet'];
}
$this->render('index', array('model'=>$model));
}
以下是索引页面代码:
$pageSize = Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);
echo CHtml::dropDownList('pageSize',$pageSize,array(5=>5,10=>10,15=>15,20=>20,25=>25,30=>30),
array('onchange'=>"$.fn.yiiListView.update('meet-greet-grid',{ data:{pageSize: $(this).val() }})",
'empty'=>'-- Select Page Range --','style'=>'width:100%;'));
$this->widget('zii.widgets.CListView',array(
'id'=>'meet-greet-grid',
'dataProvider'=>$model->candidateSearch(),
'itemView'=>'_profile_list',
'template'=>'{summary}{pager}{items}',
'summaryText'=>'Result {start} - {end} of {count} results',
});