Home > Backend Development > PHP Tutorial > yii2 resetful api 路由404

yii2 resetful api 路由404

WBOY
Release: 2016-06-06 20:07:11
Original
1655 people have browsed it

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

路由也写了
'urlManager' => [

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

        ],
    ],
    
    </action></controller></action:></controller:></action></controller></id:></action:></controller:></controller></id:></controller:></code>
Copy after login
Copy after login

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

回复内容:

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

路由也写了
'urlManager' => [

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

        ],
    ],
    
    </action></controller></action:></controller:></action></controller></id:></action:></controller:></controller></id:></controller:></code>
Copy after login
Copy after login

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

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

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

'modules' => [

<code>    'v1' => [
        'basePath' => '@app/modules/v1',
        'class' => 'app\modules\v1\Model',
    ],
],
</code>
Copy after login

注意:modules和components同级

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template