作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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 Controller :
<?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'));
}
}
}
希望有人能帮忙。预先感谢您
最佳答案
我找到了解决方案。这不是代码的问题,而是我的“ body ”的问题。我必须在 Postman chrome 扩展中从 form-data 切换到 x-www-form-urlencoded,现在 put 方法工作正常。
关于php - PUT 方法不起作用(CodeIngiter + Codeigniter 休息服务器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33064048/
我正在使用 Codeigniter 3.01 和 Codeigniter rest server 我在 put 方法中遇到问题。当我通过 put 方法运行 http://codeang.si/api/
我正在使用 Codeigniter 3.01 和 Codeigniter rest server 我在 put 方法中遇到问题。当我通过 put 方法运行 http://codeang.si/api/
我是一名优秀的程序员,十分优秀!