Let's assume I have this class at codeigniter:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller
{
function header(){
$this->load->model("options_model");
$data['options'] = $this->options_model->get_options();
$this->load->view("header", $data);
}
function content(){
$this->load->view("content");
// ...
}
function footer(){
$this->load->model("options_model");
$data['options'] = $this->options_model->get_options();
$this->load->view("footer", $data);
}
function index(){
$this->header();
$this->content();
$this->footer();
}
}
As you see, I repeated calling options_model and the method get_options at both header and footer. Then, at index I called header and footer. How can I avoid repeating methods at this cases. Or what is the best way for cases like this?