Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Register extends CI_Controller {
- private $API = "";
- function __construct()
- {
- parent::__construct();
- $this->API = "http://localhost/lawyer-online-apps/api";
- $this->load->library('session');
- $this->load->library('curl');
- $this->load->helper('form');
- $this->load->helper('url');
- }
- function index()
- {
- $this->load->view('v_register');
- }
- function register_action()
- {
- $data = array(
- 'username' => $this->input->post('username'),
- 'password' => $this->input->post('password'),
- 'email' => $this->input->post('email'),
- 'level' => 2,
- );
- $insert = $this->curl->simple_post($this->API.'/user', $data, array(CURLOPT_BUFFERSIZE => 10));
- if($insert){
- $this->session->set_flashdata('hasil','Insert Data Berhasil');
- } else {
- $this->session->set_flashdata('hasil','Insert Data Gagal');
- }
- $user = json_decode($this->curl->simple_get($this->API.'/user?username='.$data['username']));
- $id = $user[0]->id_user;
- $this->add_client($id);
- }
- function add_client($id)
- {
- $data = array(
- 'nama_client' => $this->input->post('nama_client'),
- 'tgl_lahir' => $this->input->post('tgl_lahir'),
- 'jns_kelamin' => $this->input->post('jns_kelamin'),
- 'alamat' => $this->input->post('alamat'),
- 'no_hp' => $this->input->post('no_hp'),
- 'id_user' => $id
- // $foto = $this->input->post('foto');
- );
- $insert = $this->curl->simple_post($this->API.'/client', $data, array(CURLOPT_BUFFERSIZE => 10));
- if($insert){
- echo "berhasil";
- $this->session->set_flashdata('hasil','Insert Data Berhasil');
- } else {
- echo "gagal";
- $this->session->set_flashdata('hasil','Insert Data Gagal');
- }
- redirect(base_url("main/login"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement