1

我只想在导航栏中为登录用户添加配置文件。我在 dektrium yii2-user 文档中找到了 /user/profile/show 。

但它说:

显示用户的个人资料(需要 id 查询参数)

如何在需要id查询参数的标签中实现/user/profile/show?

提前致谢

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>';
}

当我使用上面的代码并单击配置文件导航栏时,它显示错误请求(#400),缺少所需参数:id。是的,我知道因为没有定义 id 查询参数。

4

1 回答 1

0

您可以像这样添加id到参数:

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

url参数在数组的情况下使用Url::to()方法处理,因此您可以将附加参数作为键值对传递。

于 2016-08-01T09:43:28.307 回答