您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

yii2 resetful api 路由404

2024/4/27 10:44:05发布4次查看
yii2 restful api 使用的advanced 版本,按照教程搭建的api
路由也写了
'urlmanager' => [
'enableprettyurl' => true, 'enablestrictparsing' => true, 'showscriptname' => false, 'rules' => [ [ '/' => '/view', '//' => '/', '/' => '/', 'class' => 'yii\reset\urlrule', 'controller' => [ 'v1/user' ] ] ], ],

为什么按照文档的路由规则访问就提示404呢:
http://localhost/api/v1/users
回复内容: yii2 restful api 使用的advanced 版本,按照教程搭建的api
路由也写了
'urlmanager' => [
'enableprettyurl' => true, 'enablestrictparsing' => true, 'showscriptname' => false, 'rules' => [ [ '/' => '/view', '//' => '/', '/' => '/', 'class' => 'yii\reset\urlrule', 'controller' => [ 'v1/user' ] ] ], ],

为什么按照文档的路由规则访问就提示404呢:
http://localhost/api/v1/users
应该是 http://localhost/v1/users
在你的配置文件中:web.php 中添加modules,代码如下:
'modules' => [
'v1' => [ 'basepath' => '@app/modules/v1', 'class' => 'app\modules\v1\model', ],],
注意:modules和components同级
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录