I didn't find a similar topic, so I'm asking:
How to get over the problem of repeating the same model queries for all my CodeIgniter controller functions? For my site, I have to build my header and footer upon nearly same repeating database queries like this:
class Main extends CI_Controller
{
public function aboutus()
{
$this->load->model("read_db");
$commondata["title"] = "Company - ".lang("aboutus");
$commondata["mainmenu"] = $this->read_db->db_mainmenu();
$commondata["mainprodcat"] = $this->read_db->db_allprodmaincat();
$commondata["bestselling"] = $this->read_db->db_bestselling();
$commondata["brochures"] = $this->read_db->db_allbrochures();
$this->load->view("headerview", $commondata);
$contentdata["aboutus"] = $this->read_db->db_aboutus();
$this->load->view("view_aboutus", $contentdata);
$this->load->view("footerview");
}
public function contact()
{
$this->load->model("read_db");
$commondata["title"] = "Company - ".lang("contact");
$commondata["mainmenu"] = $this->read_db->db_mainmenu();
$commondata["mainprodcat"] = $this->read_db->db_allprodmaincat();
$commondata["bestselling"] = $this->read_db->db_bestselling();
$commondata["brochures"] = $this->read_db->db_allbrochures();
$this->load->view("headerview", $commondata);
$contentdata["aboutus"] = $this->read_db->db_contact();
$this->load->view("contactview", $contentdata);
$this->load->view("footerview");
}
*further functions like this*
}
Is there any option to outsource the same repeating model calls to another function or file? Thanks so much for any suggestions.