从模型中显示yii2数据时出错

时间:2016-07-14 10:10:06

标签: php yii2 yii2-advanced-app

这是控制器操作列表,如果用户角色不是超级用户,则应在用户表中显示用户

 public function actionList()
{
    $dataProvider = new ActiveDataProvider([
        'query'=>User::find()->where(['not', 'is_super']),
        'pagination' => [
            'pageSize' => 20,
        ],
    ]);

    return $this->render('list', ['dataProvider'=>$dataProvider]);
}

可能是什么问题

2 个答案:

答案 0 :(得分:1)

将您的查询更改为

'query' => User::find()->where(['<>','is_super',1]),

或者,

<?php
$super = 1; 
$dataProvider = new ActiveDataProvider([
  'query' => User::find()->where(['<>','is_super',$super]),
  'pagination' => [
      'pageSize' => 20,
  ],
]);
?>

答案 1 :(得分:1)

尝试:

'query' => User::find()->where('is_super<>:is_super',[':is_super' => 1]),