<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Wilayah extends CI_Controller {
  public function __construct(){
    parent::__construct();
    $this->load->database();
  }

  // public function kota($provinsi_id = null){
  //   $prov = $provinsi_id ?: $this->input->get('provinsi_id');
  //   $rows = $this->db->where('id_provinsi', $prov)->order_by('kota_nama','asc')->get('reg_kota')->result();
  //   $this->output->set_content_type('application/json')->set_output(json_encode($rows));
  // }

  // public function kecamatan($kota_id = null){
  //   $kota = $kota_id ?: $this->input->get('kota_id');
  //   $rows = $this->db->where('id_kota', $kota)->order_by('nama_kecamatan','asc')->get('reg_kecamatan')->result();
  //   $this->output->set_content_type('application/json')->set_output(json_encode($rows));
  // }

  // public function desa($kecamatan_id = null){
  //   $kec = $kecamatan_id ?: $this->input->get('kecamatan_id');
  //   $rows = $this->db->where('id_kecamatan', $kec)->order_by('nama_desa','asc')->get('reg_desa')->result();
  //   $this->output->set_content_type('application/json')->set_output(json_encode($rows));
  // }

	 public function provinsi(){
    $rows = $this->db->select('provinsi_id, nama_provinsi')->order_by('nama_provinsi')->get('reg_provinsi')->result();
    $this->output->set_content_type('application/json')->set_output(json_encode($rows));
  }
  public function kota($prov){
    $rows = $this->db->where('id_provinsi', $prov)->select('kota_id, kota_nama')->order_by('kota_nama')->get('reg_kota')->result();
    $this->output->set_content_type('application/json')->set_output(json_encode($rows));
  }
  public function kecamatan($kota){
    $rows = $this->db->where('id_kota', $kota)->select('kecamatan_id, nama_kecamatan')->order_by('nama_kecamatan')->get('reg_kecamatan')->result();
    $this->output->set_content_type('application/json')->set_output(json_encode($rows));
  }
  public function desa($kec){
    $rows = $this->db->where('id_kecamatan', $kec)->select('desa_id, nama_desa')->order_by('nama_desa')->get('reg_desa')->result();
    $this->output->set_content_type('application/json')->set_output(json_encode($rows));
  }
}
