yii 如何根据不同的ID创建两个按钮

swvgeqrz  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(130)

我试图创建两个按钮,基于是否满足某个条件。我做错了什么,只有一个按钮被创建,这是一个错误的开始。
有一个称为onDuty的条件,当一个团队的成员在值班时为真。一个成员可以在多个团队中,一个团队可以容纳多个成员。因此,只要一个团队的成员不在值班(onDuty = false),我想显示一个按钮,让他能够为自己分配职责。
以下是我到目前为止一直在努力做的事情:

$user = User::find()->where(['user.iduser' => Yii::$app->user->identity->iduser])->all();
    foreach ($user as $team) {
        $userTeams = $team->teamIdteams;
        foreach ($userTeams as $teams) {
            $teamId = $teams->idteam;
        }
        $userAndTeam = UserAndTeams::find()->where(['userid' => Yii::$app->user->identity->iduser])->andWhere(['teamid'=>$teamId])->all();
        foreach ($userAndTeam as $userAndTeams) {
            // Here I fail to get it done correctly.
            if ($userAndTeams->onduty !== true) {
                echo Html::a('<span class="btn-label">'.$teams->name.'</span>', 
               ['activate', 'id' => Yii::$app->user->identity->iduser, 'team' => $teamId],
               ['class' => 'btn btn-primary']);
            }
        }
    }
yyyllmsg

yyyllmsg1#

算了,我有时候是个白痴...

$user = User::find()->where(['user.iduser' => Yii::$app->user->identity->iduser])->all();
    foreach ($user as $team) {
        $userTeams = $team->teamIdteams;
        foreach ($userTeams as $teams) {
            $teamId = $teams->idteam;
            $userAndTeam = UserAndTeams::find()->where(['userid' => Yii::$app->user->identity->iduser])->andWhere(['teamid'=>$teamId])->all();
            foreach ($userAndTeam as $userAndTeams) {
                // Here I fail to get it done correctly.
                if ($userAndTeams->onduty !== true) {
                    echo Html::a('<span class="btn-label">'.$teams->name.'</span>', 
                   ['activate', 'id' => Yii::$app->user->identity->iduser, 'team' => $teamId],
                   ['class' => 'btn btn-primary']);
                }
            }
        }
    }

相关问题