Rumah >pembangunan bahagian belakang >tutorial php >yii2 resetful api 路由404
yii2 restful api 使用的advanced 版本,按照教程搭建的api
路由也写了
'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>
为什么按照文档的路由规则访问就提示404呢:
http://localhost/api/v1/users
yii2 restful api 使用的advanced 版本,按照教程搭建的api
路由也写了
'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>
为什么按照文档的路由规则访问就提示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>
注意:modules和components同级