N
N
Nikola_Vetrov2019-03-07 19:04:46
Yii
Nikola_Vetrov, 2019-03-07 19:04:46

YII2 how to make frontend button visible to admin only?

I need to hide some elements in the frontend if the admin is not logged into the admin. How can you tell in the frontend if a user is logged in to the backend? Who knows?

<a class="btn btn-primary" href="/backend/web/shop/product/update?id=<?=$product->id;?>" target="blank">РЕДАКТИРОВАТЬ</a>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
padlyuck, 2019-03-07
@padlyuck

<?php if(Yii::$app->user->identity && Yii::$app->user->identity->getIsAdmin()):?>
<a class="btn btn-primary" href="/backend/web/shop/product/update?id=<?=$product->id;?>" target="blank">РЕДАКТИРОВАТЬ</a>
<?php endif; ?>

something like this

N
Nikola_Vetrov, 2019-03-08
@Nikola_Vetrov

use
'identityClass' => 'dektrium\user\models\User',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question