小编rob*_*obr的帖子

带有多个控制器的 Yii2 Rest API 额外模式

我的 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
            ]
        ]

    ],
],
Run Code Online (Sandbox Code Playgroud)

用户/登录错误也是如此。请注意,它正在寻找 v1/user/view 操作

 {
    "name": "Not Found",
    "message": "Page not …
Run Code Online (Sandbox Code Playgroud)

yii2 yii2-advanced-app

3
推荐指数
1
解决办法
6509
查看次数

标签 统计

yii2 ×1

yii2-advanced-app ×1