【问题标题】:How to save data from http request using codeigniter restful如何使用codeigniter restful从http请求中保存数据
【发布时间】:2016-09-09 13:11:27
【问题描述】:

我正在使用 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方法保存数据?

【问题讨论】:

    标签: web-services codeigniter rest restful-authentication


    【解决方案1】:

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

    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);
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 2019-08-12
      • 1970-01-01
      相关资源
      最近更新 更多