暗桔子

暗桔子

这家伙有点懒,还没写个性签名!

  • 财富值420
  • 威望值0
  • 总积分510

个人信息

  • 回复了 的回答

    今天我也碰到类似问题了:

    http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html
    

    根据上面这个官网教程写的例子,访问时是有问题的:
    访问以下网址时报404错误(无此页面):

    http://localhost/users/5
    

    正确的写法是:(应返回id=5的记录详情信息)

    http://localhost/user/5
    

    需要注意的是,访问列表信息的链接是正确的(要用复数形式):

    http://localhost/users
    

    如果要保证访问列表信息和详情信息时都使用单数形式,需要在config\main.php加个参数:

    'pluralize'=>false,
    

    即:

    D:\phpwork\advanced\frontend\config\main.php
            'urlManager' => [
                'enablePrettyUrl' => true,
                'enableStrictParsing' => true,
                'showScriptName' => false,
                'rules' => [
                    [
                        'class' => 'yii\rest\UrlRule',
                        'controller' => 'user',
                        'pluralize'=>false,
                    ],
                ],
            ],
    

    多谢,我再试试

  • 回复了 的回答

    今天我也碰到类似问题了:

    http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html
    

    根据上面这个官网教程写的例子,访问时是有问题的:
    访问以下网址时报404错误(无此页面):

    http://localhost/users/5
    

    正确的写法是:(应返回id=5的记录详情信息)

    http://localhost/user/5
    

    需要注意的是,访问列表信息的链接是正确的(要用复数形式):

    http://localhost/users
    

    如果要保证访问列表信息和详情信息时都使用单数形式,需要在config\main.php加个参数:

    'pluralize'=>false,
    

    即:

    D:\phpwork\advanced\frontend\config\main.php
            'urlManager' => [
                'enablePrettyUrl' => true,
                'enableStrictParsing' => true,
                'showScriptName' => false,
                'rules' => [
                    [
                        'class' => 'yii\rest\UrlRule',
                        'controller' => 'user',
                        'pluralize'=>false,
                    ],
                ],
            ],
    

    我也是按照文档配置的,不管怎么访问都是 404 = =# 崩溃

  • 2017-06-22 已签到
    连续签到4天,获得了20个金钱
  • 2017-06-21 已签到
    连续签到3天,获得了15个金钱
  • 发表了说说
    办公室跟烤箱似的...哎
  • 回复了 的说说
    分手五年,她今天结婚了!
    听到消息后,赶紧 new 了个对象
  • 2017-06-20 已签到
    连续签到2天,获得了10个金钱
  • 2017-06-19 已签到
    连续签到1天,获得了5个金钱
  • 2017-06-16 已签到
    连续签到2天,获得了10个金钱
  • 2017-06-15 已签到
    连续签到1天,获得了5个金钱
主管 等级规则
510/1000
资料完整度
10/100
用户活跃度
0/100

Ta的关注

1

Ta的粉丝

0

Ta的访客

4