dongyupan4850 2015-09-14 05:51
浏览 174
已采纳

状态404未找到:yii2 RESTful API PUT方法

I'm following this link to build a set of RESTful APIs: http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html

First, create a controller as follows,

class RestorderController extends AbstractRestController {
    public $modelClass = 'app\modules\duangorder\models\Order';
}

Then, modify the configuration about the urlManager component in my application configuration:

'urlManager' => [
    'class' => 'yii\web\UrlManager',
    'enablePrettyUrl' => true,
    'enableStrictParsing' => true,
    'showScriptName' => false,
    'rules' => [
        ['class' => 'yiiest\UrlRule', 'controller' => 'duangorder/restorder'],
    ],
],

Trying it Out

GET http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder&token=gh_9831478f66cb

works fine, can get json output.

But when I: PUT http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/1 it's said Status 404 Not Found

Where is the problem? Thanks...

updated:

now I think should add update in url:

curl -l -H "Accept: application/json" -H '"processed":"0"' -X PUT -d '{"processed":"0"}' "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1"

{"id":1,"token":"gh_9831478f66cb","order_id":"143978240336383","openid":"oPuB9wkVKTXn9AZ9idM-XqhUvxh0","table_id":0,"ctime":1439782403,"phone":"13211675827","address":"address","remark":"quick","detail":"{\"4\":{\"num\":2,\"id\":\"4\",\"name\":\"\\u86cb\\u7092\\u996d\",\"price\":\"10.00\",\"total\":20},\"6\":{\"num\":1,\"id\":\"6\",\"name\":\"\\u626c\\u5dde\\u7092\\u996d\",\"price\":\"10.00\",\"total\":\"10.00\"},\"5\":{\"num\":1,\"id\":\"5\",\"name\":\"\\u51b0\\u6dc7\\u51cc\",\"price\":\"8.00\",\"total\":\"8.00\"}}","name":"tingjun","processed":"1","paid":"0"}

but processed's still not be updated...

  • 写回答

2条回答

  • dongyuan1902 2015-09-18 03:23
    关注
    curl -l  -X PUT -d processed=1 "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1"
    
    curl -l  -X PUT -d processed=0 "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记