Passing chunk of code to every controller |
09-12-2015, 02:28 AM
(This post was last modified: 09-12-2015, 08:14 AM by Keky. Edit Reason: clarification )
Hi,
I want to display some data on every page (like latest news, latest comments etc). So I created the Latest_model.php and autoload it. For example this is the simple function for getting the latest news. Code: public function get_latest_news() I put this in my template view (sidebar.php) Code: <?php foreach ($latest_news as $latest_news_item): ?> Now, let's look at some controller, for example History.php (which main function is to show history stuff in content template). Code: public function index() I want this only in history.php. So, now finally for my main problem. If I want to display latest news, comments etc... in the sidebar on every page, I have to put these lines in EVERY controller Code: $data['latest_news'] = $this->latest_model->get_latest_news(); How can I pass the code for displaying latest things without the need to writing it to every controller? |
Messages In This Thread |
Passing chunk of code to every controller - by Keky - 09-12-2015, 02:28 AM
RE: Passing chunk of code to every controller - by includebeer - 09-12-2015, 03:31 PM
RE: Passing chunk of code to every controller - by Keky - 09-13-2015, 01:33 AM
|