accella nut
accella nut

Reputation: 1

get the variable value from the admin view in the model yii

This is code at view admin

<h2>User: <?php echo $user->id ?></h2>

in view appears 3 as user id

this in model

$criteria=new CDbCriteria;
    $doc = $user->id; //desc id
    if(Yii::app()->user->id=='1'){
        $user = User::model()->findByPk(Yii::app()->user->id);
        $userLogin = $user->login;

        $criteria->addCondition("user_id= $doc");
    }

$doc is undifined,, how get value $user->id from view admin

Upvotes: -1

Views: 53

Answers (1)

Deus chami
Deus chami

Reputation: 52

Implement your user class with IdentityInterface yii\web\IdentityInterface In your configuration file

'user' => 
[
    'identityClass' => 'app\models\User', 
]

Then You may use this code to get user id in your view files as

$user = \Yii::$app->user->identity;
if (!empty($user){
   echo "<h2>User: {$user->id}</h2>";
}

Upvotes: -1

Related Questions