如何在Yii2中禁用按钮 [英] How to Disable a button in Yii2
本文介绍了如何在Yii2中禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试在用户未登录时禁用创建项目 按钮
,该按钮将隐藏
或禁用
.
I'm trying to disable the Create Project Button
when the user is not logged in, the button will Hide
or disable
.
这是我的病情:
<p>
<?php
if (Yii::$app->user->isGuest) {
Html::a('Create a Project', ['create'], ['class' => 'btn btn-primary btn-xs']);
} elseif(Yii::$app->user->identity->username) {
Html::a('Create a Project', ['create'], ['class' => 'btn btn-success']);
}
?>
</p>
正在运行,但是,当用户登录时,该按钮已经隐藏!
如何在Yii2中禁用或隐藏按钮并解决该问题?
How can disable or hide the button in Yii2 and fix that problem?
有关于它的任何教程吗?
is there any tutorial about that?
推荐答案
如果仅在用户中检查已记录的
,则使用!Yii :: $ app-> user-> isGuest
而您忘记了 echo
:
If you are just checking for logged
in user then Use !Yii::$app->user->isGuest
and you forget echo
:
if (!Yii::$app->user->isGuest) {
echo Html::a('Create a Project', ['create'], ['class' => 'btn btn-primary btn-xs'])
}
这篇关于如何在Yii2中禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文