I have used dektrium/yii2-user in my application.
And there is a method named getID() in User.php of vendor/dektrium and this method can be accessed by Yii::$app->user->getID() and returns id of the logged in user.
However, there is another method named getProfile() whose function is to return complete profile details of currently logged in user. But, this method is giving 500-internal server error.
exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: yii\web\User::getProfile()' in ... ...
I Googled the issue but found nothing... Help me folks..
I believe that you can get the profile of the currently logged in user like this:
because
Yii::$app->user->identityreturns the current user - theUserobject.You are confusing Yii's web user object with the user model :)
EDIT:
Yii::$app->useris referring toyii\web\User- the application component that manages the user authentication status.You ask that User component to get the 'identity' which is :
In this case, Dektrium User model implements the
IdentityInterfaceand you are able to callgetIdon it and get the id for the User model.This code:
Will return the
Profilemodel data associated with theUserAnd you can access it's fields directly:
See
dektrium\user\models\Profilefor details.People always gets confused about yii\web\User, the IdentityInterface and the User model.. Myself included :p