I figured a way how to combine two array outputs from a function in another function in the Codeigniter model class. It works well as I expected, but I suspect that this way is not the correct way.
public function get_job_detail($job_id){
$this->db->from('jobs');
$this->db->where('id', $job_id);
$job_details = $this->db->get();
$jobdetails = $job_details->row();
$jobcompany = $this->get_company_details($jobdetails->company_id);
$foo = array();
foreach($jobdetails as $key=>$value){
$foo[$key]=$value;
}
foreach ($jobcompany as $key => $value) {
$foo[$key]=$value;
}
return $foo;
}
public function get_company_details($company_id){
$this->db->from('companies');
$this->db->where('id', $company_id);
$query = $this->db->get();
return $query->row();
}
So in the view page, I normally access the values by using the echo $myvariable->xyz
but for some reason the return foo is not an object, therefore i had to access by using the array style echo $myvariable['xyz']
. I have been looking around for answers but I couldn't find any (or maybe i am not using the correct keywords).
Is there suppose to be a correct way? or Codeigniter way to do this??
Many thanks!