isSuperAdmin

I’m having a little bit of trouble with this code. I’m using the basic app, but have copied the idea of the advanced app user.php.

So far I have this:




class User extends ActiveRecord implements IdentityInterface

{


    // variable to display admins

    private $_isSuperAdmin = null;


    // update these with admin emails

    public $superAdmin = ['j@j.com'];


    /**

     * Returns whether the logged in user is an administrator.

     *

     * @return boolean the result.

     */

    public function getIsSuperAdmin()

    {

        if ($this->_isSuperAdmin !== null) {

            return $this->_isSuperAdmin;

        }


        $this->_isSuperAdmin = in_array('j@j.com', $superAdmin);

        return $this->_isSuperAdmin;

    }

}



I’m trying to basically be able to recognize an email address on login and set a variable to identify someone as an admin and then be able to do something like this

(isset(Yii::$app->user->isSuperAdmin) == true ? ‘Admin’ : ‘Standard’); to determine which menu items to display.

When I’m just testing this by printing out if the $var exists it’s always null. Even if I explicitly set it in the User.php to true.

What am I doing wrong here? :unsure:

You’re not referring to the object variable in this line:




$this->_isSuperAdmin = in_array('j@j.com', $superAdmin);



$superAdmin should be $this->superAdmin.

Hi Keith,

Thanks for your help. That doesn’t seem to fix the problem. Whatever I seem to set in the user.php model even if I just set the $var as true doesn’t seem to be reflected.

I have just been calling it from the index.php view just to confirm and print out it’s value.