Rohitashv Singhal
Rohitashv Singhal

Reputation: 4557

How to get user id of logged in user

I want to ask one question, that if I want to get the id of any user in config/main.php file of yii, then how can I get this ? If any one has idea please tell ?

Thanks

Upvotes: 0

Views: 265

Answers (1)

DarkMukke
DarkMukke

Reputation: 2489

Your config/main.php is used to build your application, hence it is not possible to get data in there that is only available after Yii::app() is available.

But you can get your user id by Yii::app()->user->id;

You can use that everywhere, for example in Controller->init() that will execute before your SiteController is ran.

You can still set your language after you config.

Yii::app()->language = Helper::getLanguageFromUser(Yii::app()->user->id);

Ofc Helper is a fictive class here, it can be any thing. See an example here.

Upvotes: 1

Related Questions