我使用Codeigniter 3.01和Codeigniter rest server
我在put方法上遇到了问题。
当我通过put方法运行http://codeang.si/api/task/id/2
时(查看附图)并尝试var_dump($data);
我得到这个"空"结果:
array (size=3)
'task' => boolean false
'active' => boolean false
'date_c' => string '2015-10-11 12:10' (length=16)
这是我的api控制器:
<?php
require(APPPATH.'libraries/REST_Controller.php');
class Api extends REST_Controller{
function tasks_get(){
// respond with information about a task
$task = $this->tm->get_all();
if($task){
$this->response($task, 200);
}else{
$this->response(NULL, 404);
}
}
function task_get(){
// respond with information about a task
if(!$this->get('id')){
$this->response(NULL, 400);
}
$task = $this->tm->get($this->get('id'));
if($task){
$this->response($task, 200);
}else{
$this->response(NULL, 404);
}
}
function task_post(){
// create task
$data = array(
'task' => $this->post('task'),
'active' => $this->post('active'),
'date_c' => date("Y-m-d h:i:s")
);
$result = $this->tm->create( $data);
if($result === FALSE){
$this->response(array('status' => 'failed'));
}else{
$this->response(array('status' => 'success'));
}
}
function task_put(){
// update task
$id = $this->get('id');
$data = array(
'task' => $this->put('task'),
'active' => $this->put('active'),
'date_u' => date("Y-m-d h:i:s")
);
var_dump($data, $id);
die();
$result = $this->tm->update($this->get('id'), $data);
if($result === FALSE){
$this->response(array('status' => 'failed'));
}else{
$this->response(array('status' => 'success'));
}
}
function task_delete(){
//delete a task and respond with a status/errors
$result = $this->tm->delete($this->get('id'));
if($result === FALSE){
$this->response(array('status' => 'failed'));
}else{
$this->response(array('status' => 'success'));
}
}
}
我希望有人可以提供帮助。 提前谢谢