How to print the user role in the Yii 2 GridView widget? I have tried with code:
public function getUserRole ($ id) {$ roles = \ Yii :: $ app-> authManager-> getRolesByUser ($ ID);
$ role = ''; Forex currency ($ roles as $ key = & gt; $ value) {$ role = $ key; } $$ -> role = $ role; }
In the user model class but it is not working. Each user has played only one role, many thanks for any help.
OK, I got it!
See:
$ Detector, 'FilterModel' = & gt; $ SearchModel, 'Columns' = & gt; [[' Class' = & gt; yii \ grid \ SerialColumn ' ] '//' auth_key ', //' password_hash '//' status_, '//' id ', [' label '= & gt; najwa ujatakunika', 'value' = & gt; 'username'], '' Created_at ', /' password_reset_token ',' email: email ', [' labels' = & gt; 'rolla', 'value' = & gt; 'userRole' / 'updated_at', ['class' = & gt; ; 'Yii \ grid \ ActionColumn'],],]); ? & Gt; Method in user model class: public function getUserRole () {$ roles = \ Yii :: $ app- & gt; AuthManager- & gt; GetRolesByUser ($ this-> ID); $ Roll = ''; Forex currency ($ roles as $ key = & gt; $ value) {$ role = $ key; } Role of return; }
and in the UserSearch class attribute:
public $ userRole; [[UserRole '],' safe ']
/ P>
No comments:
Post a Comment