CRUD pages for Users gives error

I’m currently doing a custom User class for my identity class. I created a table in my DB with the following attributes:

Table Name: users

ID INT

Email VARCHAR(256)

Password VARCHAR(256)

AuthKey VARCHAR(256)

Username VARCHAR(256)

AccessToken VARCHAR(256)

I used Gii to generate the model from the DB, the controller, and the views. Here is the User class:




<?php


namespace app\models;


use Yii;

use yii\base\NotSupportedException;

use yii\db\ActiveRecord;

use yii\helpers\Security;

use yii\web\IdentityInterface;




/**

 * This is the model class for table "users".

 *

 * @property integer $ID

 * @property string $Email

 * @property string $Password

 * @property string $AuthKey

 * @property string $Username

 * @property string $AccessToken

 */

class User extends ActiveRecord implements IdentityInterface

{

    /**

     * @inheritdoc

     */

    public static function tableName()

    {

        return 'users';

    }


    /**

     * @inheritdoc

     */

    public function rules()

    {

        return [

            [['Email', 'Password', 'Username', 'AccessToken'], 'string', 'max' => 256],

            [['AuthKey'], 'string', 'max' => 32]

        ];

    }


    /**

     * @inheritdoc

     */

    public function attributeLabels()

    {

        return [

            'ID' => 'ID',

            'Email' => 'Email',

            'Password' => 'Password',

            'AuthKey' => 'Auth Key',

            'Username' => 'Username',

            'AccessToken' => 'Access Token',

        ];

    }

    

    public static function findIdentity($id)

    {

        return static::findOne($id);

    }


    public static function findIdentityByAccessToken($token, $type = null)

    {

        return static::findOne(['AccessToken' => $token]);

    }


    public function getId()

    {

        return $this->ID;

    }


    public function getAuthKey()

    {

        return $this->AuthKey;

    }


    public function validateAuthKey($authKey)

    {

        return $this->AuthKey === $authKey;

    }


}



In the Web config file, I’ve set the User class to app\models\User and disabled Auto Login.

Now when I try to go to the Index page for User, it gives me the following error:

"PHP Warning – yii\base\ErrorException Invalid argument supplied for foreach()"

"in D:\xampp\htdocs\GameEmbargo\vendor\yiisoft\yii2\BaseYii.php"

No other part of my site throws this error, just the User section. It must have something to do with the Identity stuff, but I have no idea what. Some help is appreciated.

Your information are a bit incomplete you report the last error.

Yii provide you the entire trace.

The last error (the one on the top of the page) is the one at the foreach()

this foreach use a parameter that should be an array and it is not, here is the error.

But the problem reside on what generate the array to be passed to this foreach

Beside this you say you access to user/index,

which should call the index action of the controller which should show a user list

Start to check your code form there.

If you want more help provide more complete info.