通过在CodeIgniter中发送PUT请求来插入数据(Phil Sturgeon Rest Server)

Jek*_*ekk 3 php rest codeigniter put

我通过API中的REST CLIENT发送的PUT和POST请求之间存在差异.它在CodeIgniter中与Phil Sturgeon的REST服务器一起实现.

function station_put(){

    $data = array(
        'name' => $this->input->post('name'),
        'number' => $this->input->post('number'),
        'longitude' => $this->input->post('longitude'),
        'lat' => $this->input->post('latitude'),
        'typecode' => $this->input->post('typecode'),
        'description' => $this->input->post('description'),
        'height' => $this->input->post('height'),
        'mult' => $this->input->post('mult'),
        'exp' => $this->input->post('exp'),
        'elevation' => $this->input->post('elevation')
    );

    $id_returned = $this->station_model->add_station($data);
    $this->response(array('id'=>$id_returned,'message'=>"Successfully created."),201);


}
Run Code Online (Sandbox Code Playgroud)

此请求成功地将数据插入到服务器BUT中 - 除了id之外,它将其余值呈现为NULL.

但是,如果将函数名称更改为station_post,则会正确插入数据.

有人请指出为什么PUT请求不起作用?我使用的是最新版本的谷歌浏览器.

顺便说一下,这个API将集成到BackBone处理的应用程序中.我真的需要使用PUT吗?或者在使用post时,是否还有另一种使用骨干模型保存功能的解决方法?

Jek*_*ekk 7

终于回答了.而不是$this->input->post$this->input->put,它必须是$this->put$this->post因为数据不是来自表单.