how to get array parameter from what user type in browser with codeigniter3
this is my controller
class header extends CI_Controller{
public function index(){
$this->load->model('header_model');
$hasil = $this->header_model->getData();
var_dump($hasil);
}
}
and this is my model
class header_model extends CI_Model{
public function getData(){
$array = ["000118","000112","000117"];
$this->db->select('NOMOR_DAFTAR, TANGGAL_DAFTAR');
$this->db->where_in('NOMOR_DAFTAR',$array);
return $this->db->get('tpb_header')->result_array();
}
}
$array above i want to get from what user type in browser
You can use header(‘content-type application/json’) in codeigniter to return json array.
For example:
class header extends CI_Controller{
public function index(){
header("Content-type:application/json");
$this->load->model('header_model');
$hasil = $this->header_model->getData();
//var_dump($hasil);
echo json_encode($hasil);
}
}
finally i got the answer, but for note this not using codeigniter pure, there is librabry since method get there is no in codeigniter pure and this is the answer
class Header_model extends CI_Model {
public function getData($array = []){
$this->db->select('NOMOR_DAFTAR, TANGGAL_DAFTAR');
$this->db->where_in('NOMOR_DAFTAR',$array);
return $this->db->get('tpb_header')->result_array();
}}
class header1 extends Rest_Controller{
public function index_get(){
$array[]=$this->get('NOMOR1');
$array[]=$this->get('NOMOR2');
$this->load->model('header_model');
$hasil = $this->header_model->getData($array);
var_dump($hasil);
}}