Welcome Guest, Not a member yet? Register   Sign In
How to send post data in controller codeigniter
#5

(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

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.

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
Reply


Messages In This Thread
RE: How to send post data in controller codeigniter - by joel26 - 01-06-2015, 02:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB