我的 API 中有 2 个控制器。每个都定义了额外的模式。我的所有操作都可以正常工作,除了用户登录,这是在额外的模式中定义的。
<?
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => [ 'v1/item', 'v1/user'],
'tokens' => [
'{id}' => '<id:\\w+>', //commenting out this token allows login to return
'{type}'=>'<type:\\w+>'
],
'extraPatterns' => [
'POST {id}/image/{type}' => 'image', //from the item controller
'GET login' => 'login' // from the USER controller
]
]
],
],
用户/登录错误。请注意,它正在寻找 v1/user/view 操作
{
"name": "Not Found",
"message": "Page not found.",
"code": 0,
"status": 404,
"type": "yii\\web\\NotFoundHttpException",
"previous": {
"name": "Invalid Route",
"message": "Unable to resolve the request: v1/user/view",
"code": 0,
"type": "yii\\base\\InvalidRouteException"
}
}
如果我在 urlManager 中注释掉 ID 令牌,则用户/登录操作有效,但我的其他路由失败。