Advertisement
waydub12

Untitled

Jan 3rd, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <?php
  2.  
  3. class Register extends CI_Controller {
  4.  
  5. private $API = "";
  6.  
  7. function __construct()
  8. {
  9. parent::__construct();
  10. $this->API = "http://localhost/lawyer-online-apps/api";
  11. $this->load->library('session');
  12. $this->load->library('curl');
  13. $this->load->helper('form');
  14. $this->load->helper('url');
  15. }
  16.  
  17. function index()
  18. {
  19. $this->load->view('v_register');
  20. }
  21.  
  22. function register_action()
  23. {
  24. $data = array(
  25. 'username' => $this->input->post('username'),
  26. 'password' => $this->input->post('password'),
  27. 'email' => $this->input->post('email'),
  28. 'level' => 2,
  29. );
  30. $insert = $this->curl->simple_post($this->API.'/user', $data, array(CURLOPT_BUFFERSIZE => 10));
  31.  
  32. if($insert){
  33. $this->session->set_flashdata('hasil','Insert Data Berhasil');
  34. } else {
  35. $this->session->set_flashdata('hasil','Insert Data Gagal');
  36. }
  37.  
  38. $user = json_decode($this->curl->simple_get($this->API.'/user?username='.$data['username']));
  39. $id = $user[0]->id_user;
  40. $this->add_client($id);
  41. }
  42.  
  43. function add_client($id)
  44. {
  45. $data = array(
  46. 'nama_client' => $this->input->post('nama_client'),
  47. 'tgl_lahir' => $this->input->post('tgl_lahir'),
  48. 'jns_kelamin' => $this->input->post('jns_kelamin'),
  49. 'alamat' => $this->input->post('alamat'),
  50. 'no_hp' => $this->input->post('no_hp'),
  51. 'id_user' => $id
  52. // $foto = $this->input->post('foto');
  53. );
  54. $insert = $this->curl->simple_post($this->API.'/client', $data, array(CURLOPT_BUFFERSIZE => 10));
  55.  
  56. if($insert){
  57. echo "berhasil";
  58. $this->session->set_flashdata('hasil','Insert Data Berhasil');
  59. } else {
  60. echo "gagal";
  61. $this->session->set_flashdata('hasil','Insert Data Gagal');
  62. }
  63. redirect(base_url("main/login"));
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement