F
F
Flaker2014-07-04 01:18:35
Yii
Flaker, 2014-07-04 01:18:35

(Yii2) How to get current user model?

At the moment I am doing this:

$userModel = Yii::$app->user->identity;
// В конфиге указано: 'identityClass' => 'common\models\User'

But since identity is an object of the IdentityInterface interface , PhpStorm does not see the methods of the common\models\User model .
Here I also had a question: How to get the model of the current user ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-07-04
@Flaker

/** @var common\models\User $userModel */
$userModel = Yii::$app->user->identity;

otherwise, such things can be resolved only by plug-ins to the storm. I don’t follow the situation with Yii at the moment.

E
Eugene, 2016-12-24
@Jekshmek

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 question

Ask a Question

731 491 924 answers to any question