首页 > yii2 resetful api 路由404

yii2 resetful api 路由404

yii2 restful api 使用的advanced 版本,按照教程搭建的api

路由也写了
'urlManager' => [

        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,
        'rules' => [
            [
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                'class' => 'yii\reset\UrlRule',
                'controller' => [
                    'v1/user'
                ]
            ]

        ],
    ],
    
    

为什么按照文档的路由规则访问就提示404呢:
http://localhost/api/v1/users


在你的配置文件中:web.php 中添加modules,代码如下:

'modules' => [

    'v1' => [
        'basePath' => '@app/modules/v1',
        'class' => 'app\modules\v1\Model',
    ],
],

注意:modules和components同级


应该是 http://localhost/v1/users

【热门文章】
【热门文章】