【发布时间】:2017-09-21 14:22:21
【问题描述】:
1) 我的 Yii2 在 subfilder 中,所以我的所有链接都从 Yii/ 开始,例如 http:/localhost/Yii/settings/usertype-activitytype/type/3强>
2) 请求组件配置
'request' => [
'cookieValidationKey' => 'somecookiekey',
'baseUrl' => '/Yii',
],
3) 尝试构建菜单,当前路由是 http:/localhost/Yii/settings/usertype-activitytype/type/1 1 是路由中的 id,我应该将当前路由指定为Yii::$app->request->Nav 小部件的路径信息
尝试 1 - 没有大括号作为字符串 未找到活动元素
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => Url::current(['id' => $userType->id]),
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
尝试 2 - 使用大括号作为路线 未找到活动元素
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => [Url::current(['id' => $userType->id])]
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
尝试 3 - 从生成的路由中删除 baseUrl 查找活动元素!!!
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => [str_replace('Yii/', '', Url::current(['id' => $userType->id]))]
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
所以你应该注意到我必须使用脏 hack 来强制 Nav 使用生成的 Url,这似乎很不方便。
问题是 - 是否有办法强制 NAV 小部件识别当前活动项目?
【问题讨论】: