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条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮