Advertisement
timonte

city

Apr 20th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Checkout extends CI_Controller {
  5.  
  6. function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->library(array('template', 'cart'));
  10. $this->load->model('app_home');
  11. $this->load->library('form_validation');
  12. }
  13.  
  14. public function index()
  15. {
  16. $this->template->alfatihmart("checkout");
  17. }
  18.  
  19. public function city()
  20. {
  21.  
  22. $prov = $this->input->post('prov', TRUE);
  23. $curl = curl_init();
  24.  
  25. curl_setopt_array($curl, array(
  26. CURLOPT_URL => "http://api.rajaongkir.com/starter/city?province=$prov",
  27. CURLOPT_RETURNTRANSFER => true,
  28. CURLOPT_ENCODING => "",
  29. CURLOPT_MAXREDIRS => 10,
  30. CURLOPT_TIMEOUT => 30,
  31. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  32. CURLOPT_CUSTOMREQUEST => "GET",
  33. CURLOPT_HTTPHEADER => array(
  34. "key: b03354ea01da154f19e1d300a9497a16"
  35. ),
  36. ));
  37.  
  38. $response = curl_exec($curl);
  39. $err = curl_error($curl);
  40.  
  41. curl_close($curl);
  42.  
  43. if ($err) {
  44. echo "cURL Error #:" . $err;
  45. } else {
  46. $data = json_decode($response, TRUE);
  47.  
  48. echo '<option value="" selected disabled>kota / kabupaten</option>';
  49.  
  50. for ($i=0; $i < count($data['rajaongkir']['results']); $i++) {
  51. echo '<option value="' .$data['rajaongkir']['results'][$i]['city_id'].','.$data['rajaongkir']['results'][$i]['city_name'].'">'.$data['rajaongkir']['results'][$i]['city_name'].'</option>';
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement