有人能告诉我如何使用Phil Sturgeon Restful服务器将数据插入mysql吗? 我使用GET方法获取数据时没关系,但是当我尝试使用POST方法插入数据时,它总是像这样回应:
{"status":false,"error":"Unknown method."}
<?php defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/libraries/REST_Controller.php';
class Api extends REST_Controller
{
public function __construct()
{
parent::__construct();
$this->load->Model("user_model");
}
function register_post() {
$username = $this->post('username');
$password = $this->post('password');
$firstname = $this->post('firstname');
$lastname = $this->post('lastname');
$mobile = $this->post('mobile');
$sex = $this->post('sex');
$avatar = $this->post('avatar');
$active = $this->post('active');
$device_token = $this->post('device_token');
$fbconnected = $this->post('fbconnected');
$token = $this->post('token');
$register = array(
'username' => $username,
'password' => MD5('".$password."'),
'firstname' => $firstname,
'lastname' => $lastname,
'mobile' => $mobile,
'sex' => $sex,
'avatar' => $avatar,
'active' => $active,
'device_token' => $device_token,
'fbconnected' => $fbconnected,
'token' => $token
);
$this->user_model->register($register);
//$this->response($register, 200); // 200 being the HTTP response code
}
}
?>