我想写一个像这样的条件,例如:
Yii::$app->user->isGuest ? (
['label' => 'Sign Up', 'url' => ['/site/signup']]
):(
//do nothing
)
?:
条件可以没有else
部分吗?
修改
它被发送到数组'items' => []
,这就是为什么下面的代码不起作用的原因:
if(Yii::$app->user->isGuest)(
['label' => 'Sign Up', 'url' => ['/site/signup']];
)
完整代码:
NavBar::begin([
//somecode
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
Yii::$app->user->isGuest ? (
['label' => 'Sign Up', 'url' => ['/site/signup']]
):(
//HOW TO DO NOTHING HERE???
)
],
]);
答案 0 :(得分:2)
答案 1 :(得分:1)
您可以将其写为 -
['label' => 'Sign Up', 'url' => ['/site/signup'], 'visible' => Yii::$app->user->isGuest ]