php - codeigniter global array for a model -


in controller want declare global variable fetch areas db

currently i'm passing $data['dropdowns'] in methods in class

{ $data['dropdowns']=loading other model method $this->load->view('commons/header',$data);   }  {   $data['dropdowns']=loading other model metod $this->load->view('commons/header',$data);   }  {   $data['dropdowns']=loading other model metod $this->load->view('commons/header',$data);   }  {    $data['dropdowns']=loading other model metod $this->load->view('commons/header',$data);   } 

the thing want send $data['area'] views without having declare again , again in each method

$data['area']= $this->area_model->get_all_locations(); 

you want add global variable , per suggest use global function use using send parameter, please check below code.
note : please load model in application/config/autoload.php file

this simple demo : controller

{  $data['dropdowns']=$this->your_model_name->get_records('table_name','select field id, name');  $this->load->view('commons/header',$data);   }  {  $data['dropdowns']=$this->your_model_name->get_records('table_name','select field id, name,user_name');  $this->load->view('commons/header',$data);   } 

your model

function get_records($table_name,$field_name) {    $this->db->select("$field_name");    $this->db->from("$table_name");    $query=$this->db->get();      return $query->result_array();  } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -