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?