简体   繁体   中英

Error in yii2 data display from a model

This is the controller action list which should display users in a user table if a user role is not super

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

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

What could be the problem

Change your query to

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

Or,

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

尝试:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM