1

I just want to add Profile in navbar for logged user. And I found /user/profile/show in dektrium yii2-user docs.

But it said:

Displays user's profile (requires id query param)

How to implement /user/profile/show in label that requires id query param?

Thanks in advance

if (Yii::$app->user->isGuest) {
    $menuItems[] = ['label' => 'Signup', 'url' => ['/user/registration/register']];
    $menuItems[] = ['label' => 'Login', 'url' => ['/user/security/login']];
} else {
    $menuItems[] = ['label' => 'Profile', 'url' => ['/user/profile/show']];
    $menuItems[] = '<li>'
        . Html::beginForm(['/user/security/logout'], 'post')
        . Html::submitButton(
            'Logout (' . Yii::$app->user->identity->username . ')',
            ['class' => 'btn btn-link']
        )
        . Html::endForm()
        . '</li>';
}

When I use code above and click the Profile navbar, it said Bad Request (#400), Missing required parameters: id. Yea I know becuse of the id query param isn't defined.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
exneval
  • 43
  • 1
  • 4

1 Answers1

0

You can add id to params like so:

$menuItems[] = ['label' => 'Profile', 'url' => ['/user/profile/show', 'id' => $id]];

url parameter is processed with Url::to() method in case of array, so you can pass additional parameters as key-value pairs.

arogachev
  • 33,150
  • 7
  • 114
  • 117