Answer the question
In order to leave comments, you need to log in
(Yii2) How to get current user model?
At the moment I am doing this:
$userModel = Yii::$app->user->identity;
// В конфиге указано: 'identityClass' => 'common\models\User'
Answer the question
In order to leave comments, you need to log in
/** @var common\models\User $userModel */
$userModel = Yii::$app->user->identity;
Create a Yii.php file in PhpStorm at the root of the project
In which we list the custom components for which we want to autocomplit
<?php
/**
* Yii bootstrap file.
* Used for enhanced IDE code autocompletion.
*/
class Yii extends \yii\BaseYii
{
/**
* var BaseApplication|WebApplication|ConsoleApplication the application instance
*/
public static $app;
}
/**
* Class BaseApplication
* Used for properties that are identical for both WebApplication and ConsoleApplication
*
*
*
* @property \yii\i18n\Formatter $formatter
* @property \yii\log\FileTarget $log
* @property \yii\db\Connection $db
* @property \yii\mongodb\Connection $mongodb
* @property \yii\redis\Connection $redis
* @property \yii\ redis\Session $session
* @property \yii\swiftmailer\Mailer $mailer
* @property \common\models\user\UserReqHandler $user
*/
abstract class BaseApplication extends yii\base\Application
{
}
/**
* Class WebApplication
* Include only Web application related components here
* @property \common\components\extensions\GrestExtension $grest Extended component.
*/
class WebApplication extends yii\web\Application
{
}
/**
* Class ConsoleApplication
* Include only Console application related components here
*
* @property \common\components\extensions\GrestExtension $grest Extended component.
*/
class ConsoleApplication extends yii\console\Application
{
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question