如何使用 codeigniter 从 http 请求中保存数据 restful

How to save data from http request using codeigniter restful

我正在使用 restful 为我的 android 应用创建网络服务。我在我的应用程序中使用 Facebook 按钮登录,我想存储来自他们 Facebook 帐户的用户数据。

public function sotrefacebookuser_get(){
    $data[] = base64_decode($this->uri->segment(3));
    if(!empty($data) && $data != ""){
        $userid = $this->Api_model->savefacebookuser($data);

        if(!empty($userid)){
            $this->response(array('status'=>'success', 'massage'=> 'Your Record Save successfully'));
        } else {
            $this->response(array('status'=>'failure', 'massage'=> 'The specified data could not saved try again letter'), REST_Controller::HTTP_NOT_FOUND);
        }
    }
    else {
        $this->response(array('status'=>'failure', 'massage'=> 'The specified data could not be found'), REST_Controller::HTTP_NOT_FOUND);
    }

}

上面的代码是我的 API 控制器,它工作正常,但我知道,这不是正确的方法。

这是我的模型代码。

public function savefacebookuser($data){
    $this->_table = "front_user";
    return $this->insert($data, FALSE);
}

如何使用restful中的post方法保存数据?

在restful中,如果你想保存数据,你需要使用post请求并在正文中发送数据。

public function sotrefacebookuser_post(){
    $data = $_POST['key'];
    if(!empty($data) && $data != ""){
        $userid = $this->Api_model->savefacebookuser($data);

        if(!empty($userid)){
            $this->response(array('status'=>'success', 'massage'=> 'Your Record Save successfully'));
        } else {
            $this->response(array('status'=>'failure', 'massage'=> 'The specified data could not saved try again letter'), REST_Controller::HTTP_NOT_FOUND);
        }
    }
    else {
        $this->response(array('status'=>'failure', 'massage'=> 'The specified data could not be found'), REST_Controller::HTTP_NOT_FOUND);
    }

}