我想在cGridview使用過濾器與cActiveDataProvider但它提供了以下異常的Yii:在網格視圖CActiveDataProvider篩選提供了錯誤
CActiveDataProvider其行爲沒有方法或關閉名爲「getValidators」
請檢查下面的代碼
控制器
public function actionAdmin()
{
$admin_type=Yii::app()->user->isAdmin;
if($admin_type==1)
{
$admin_batches=WebHelper::getAllAdminBatchesInArray(Yii::app()->user->getId());
if(!empty($admin_batches))
{
$batch_list=implode(",",$admin_batches);
}
$batch_criteria="group_id IN (".$batch_list.") and status!=-1";
}
else
$batch_criteria="1 and status!=-1";
$model=new CActiveDataProvider('Users',array('criteria'=>array(
'condition'=>$batch_criteria,
)));
// print_r($model);die;
//$model->unsetAttributes(); // clear any default values
if(isset($_GET['Users']))
$model->attributes=$_GET['Users'];
$this->render('admin',array(
'model'=>$model,
));
}
查看
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'users-grid',
'dataProvider'=>$model,
'filter'=>$model,
'columns'=>array(
array(
'class'=>'CButtonColumn',
'htmlOptions'=>array('width'=>'70px'),
'buttons' => array(
'view' => array(
'imageUrl' => Yii::app()->baseUrl . '/themes/gamify/images/view-image.png'
),
'update' => array(
'imageUrl' => Yii::app()->baseUrl . '/themes/gamify/images/Edit-icon.png'
),
'delete' => array(
'imageUrl' => Yii::app()->baseUrl . '/themes/gamify/images/Delete-icon.png'
)
)
),
first_name',
'last_name',
'user_name',
'group.group_title',
//'password',
'email_id',
array(
'type'=>'raw',
'name'=>'Status',
'value'=>'($data->status==0)?"<a href=\'\' id=\'$data->user_id\' class=\'user_status Active\'>Active</a>":"<a href=\'\' id=\'$data->user_id\' class=\'user_status Inactive\'>Inactive</a>"'
),
),));?>
@ talhamalik22:你試過我的解決方案嗎? – hamed 2015-03-03 15:58:39