小编use*_*871的帖子

$ this-> post codeigniter不能与rest api一起使用

我试图用$this->post()json格式发送邮件发送的数据.我无法得到任何结果$this->post('name').

这是代码:

<?php

require(APPPATH . '/libraries/REST_Controller.php');

class user_api extends REST_Controller {

    function user_post() {

                $user = array(
                    'id' => null,
                    'firstname' => $this->post('firstname'),
                    'lastname' => $this->post('lastname')
                );

                $result = $this->user_model->insert($user);
                if ($result) {
                    $this->response($result, 200); // 200 being the HTTP response code
                } else {
                    $this->response(NULL, 404);
                }
    }

}

?>
Run Code Online (Sandbox Code Playgroud)

以json格式发送到链接的数据:http://mydomain.com/myapplication/user_api/user:

{"firstname":"test",
"lastname":"test"
}
Run Code Online (Sandbox Code Playgroud)

数据库中没有数据,因为它无法从中获取数据$this->post('firstname').

任何的想法 ????

php rest post codeigniter

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

codeigniter ×1

php ×1

post ×1

rest ×1