Skip to content
Advertisement

yii2 identity session expiry

I am new to yii2 framework and I am facing a problem with the identity. when the session timeouts or when I change my user status to inactive I am getting an error of Trying to get property of non-object from the user component.

public function getName()
{
    return Yii::$app->user->identity->username;
}

as I am retrieving this value in the header of the website, I want to redirect to login page instead of showing this error

Advertisement

Answer

As good practice you should use Access Control Filters in your controller. Please refer to this link to get an idea on how to implement authorisation in your controllers.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement