Val*_*or_ 2 php rest codeigniter
我正在使用 Codeigniter 3.01 和Codeigniter rest 服务器
我在 put 方法中遇到了问题。当我http://codeang.si/api/task/id/2通过 put 方法运行(检查附加图片)并尝试var_dump($data);得到这个“空”结果时:
array (size=3)
'task' => boolean false
'active' => boolean false
'date_c' => string '2015-10-11 12:10' (length=16)
Run Code Online (Sandbox Code Playgroud)
这是我的 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'));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望有人能帮帮忙。先感谢您
我找到了解决方案。这不是代码的问题,而是我的“身体”。我不得不在 Postman chrome 扩展中从 form-data 切换到 x-www-form-urlencoded,现在 put 方法工作正常。
| 归档时间: |
|
| 查看次数: |
3960 次 |
| 最近记录: |