How to send post data in controller codeigniter |
How to send post data in controller codeigniter to web API,,, help me
this my code in my controller $kirim = array( 't187UserName' => $this->input->post('t187UserName'), 't187Password' => $this->input->post('t187Password'), 'upassword' => $this->input->post('upassword'), 't187Email' => $this->input->post('t187Email'), 't187NamaAwal' => $this->input->post('t187NamaAwal'), 't187NamaAkhir' => $this->input->post('t187NamaAkhir'), 't187JKel' => $this->input->post('t187JKel'), 't187TelpHP' => $this->input->post('t187TelpHP'), 't187TelpRumah' => $this->input->post('t187TelpRumah'), 't187TanggalLahir' => $this->input->post('t187TanggalLahir'), 't187AlamatRumah' => $this->input->post('t187AlamatRumah') ); $params = json_encode($kirim); $ch = curl_init('http://localhost:8881/webApi/registrasiAkun'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($params)) );
curl_exec($ch) ?
you may also want to look into CURLOPT_VERBOSE: http://stackoverflow.com/questions/37570...gging-curl (01-02-2015, 11:03 AM)bclinton Wrote: curl_exec($ch) ? if I do not use CURL , how to send the post data to a web APIs,,, (my web API make use Grails Framework) And front end use Codeigniter,,, help me
I didn't say you should not use cURL. I pointed out that the code you posted does not contain a curl_exec statement. curl_exec actually performs the cURL operation
In case you do have a curl_exec statement and just did not include it in your code when you posted, I suggested looking into using CURLOPT_VERBOSE to help you debug your code. You may also want to look into using this: https://github.com/philsturgeon/codeigniter-curl It may no longer be actively maintained, but it should still work. At the very least, it may give you some ideas for setting up a codeigniter library to handle communication with your API. (01-05-2015, 10:00 AM)bclinton Wrote: I didn't say you should not use cURL. I pointed out that the code you posted does not contain a curl_exec statement. curl_exec actually performs the cURL operation I had to replace my controller like this : <?php require(APPPATH.'/libraries/REST_Controller.php'); class Pendaftaran extends REST_Controller{ // function __construct(){ // parent::__construct(); // $this->load->helper(array('form', 'url')); // $this->load->library('form_validation'); // } function index(){ $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); $this->form_validation->set_rules('t187UserName', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean'); $this->form_validation->set_rules('t187Password', 'Password', 'trim|required|min_length[5]|matches[upassword]|md5'); $this->form_validation->set_rules('upassword', 'Ulangi Password', 'trim|required'); $this->form_validation->set_rules('t187Email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('t187NamaAwal', 'Nama Awal', 'trim|required'); $this->form_validation->set_rules('t187NamaAkhir', 'Nama Akhir', 'trim|required'); $this->form_validation->set_rules('t187JKel', 'Jenis Kelamin', 'required'); $this->form_validation->set_rules('t187TelpHP', 'Telepon Celular', 'trim|required|numeric'); $this->form_validation->set_rules('t187TelpRumah', 'Telepon Rumah', 'trim|numeric'); $this->form_validation->set_rules('t187TanggalLahir', 'Tanggal Lahir', 'trim|required'); $this->form_validation->set_rules('t187AlamatRumah', 'Alamat Rumah', 'trim|required|max_length[150]'); $data=array( 'title'=>'Registrasi Akun' ); if ($this->form_validation->run() == FALSE){ $this->load->view('element/v_header',$data); $this->load->view('pages/v_pendaftaran'); $this->load->view('element/v_footer'); }else{ // menyimpan data $kirim = array( 't187UserName' => $this->input->post('t187UserName'), 't187Password' => $this->input->post('t187Password'), 'upassword' => $this->input->post('upassword'), 't187Email' => $this->input->post('t187Email'), 't187NamaAwal' => $this->input->post('t187NamaAwal'), 't187NamaAkhir' => $this->input->post('t187NamaAkhir'), 't187JKel' => $this->input->post('t187JKel'), 't187TelpHP' => $this->input->post('t187TelpHP'), 't187TelpRumah' => $this->input->post('t187TelpRumah'), 't187TanggalLahir' => $this->input->post('t187TanggalLahir'), 't187AlamatRumah' => $this->input->post('t187AlamatRumah') ); //$params = json_encode($kirim); $this->load->library('rest', array( 'server' => 'http://localhost:9091/dms-webapi/webApi/registrasiAkun/', 'http_user' => 'admin', 'http_pass' => 'admin', 'http_auth' => 'basic' // or 'digest' )); $result = $this->rest->post($kirim, 'json'); //echo $user->name; if(isset($result->status) && $result->status == 'ok'){ echo 'Berhasil daftar.'; }else{ echo 'Daftar gagal'; } // $this->load->view('element/v_header',$data); // $this->load->view('errorv/v_error'); // $this->load->view('element/v_footer'); } } } but I found the error again be : Unable to load the requested file: helpers/inflector_helper.php help me again
add this to your helper loader:
PHP Code: $this->load->helper(array('form', 'url','inflector')); |
Welcome Guest, Not a member yet? Register Sign In |