GEOFFREY MWANGI GEOFFREY MWANGI - 4 months ago 23
PHP Question

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

Answer

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,
  ],
]);
?>
Comments