I’m finding that I need to write a lot of duplicate code given that I’m unable to call functions from other controllers. For example, here the news feed stuff is repeated throughout my code where I do something specific to one controller then need to load my news feed like so. Is this typical of MVC, am I missing some codeigniter tool, or am I just doing it wrong?
function register_user() {
//registration stuff
$userName = $this->input->post('username');
$email = $this->input->post('email');
$data = array(
'name' => $userName,
'email' => $email
);
$this->load->model('user_model');
$this->user_model->register_user($data);
//news feed stuff
$this->load->model('NewsFeed_model');
$data['queryMovies'] = $this->NewsFeed_model->getPublications();
$this->load->view('news_feed_view', $data);
}
You can either create a library or a helper that you can call from all your controllers or you can create a common controller base class (my personal favorite) with the common functions and have all your CI controllers inherit from it.