Reputation: 3637
I have a news blocks. These news are got from the database. What I need is to write $this->load->view('news');
on any of my pages and for the news to display. This implies that 'news' is a view and has display logic for the news AND has logic that calls the controller which calls the model to get the news (this part is what bothers me). I don't want to pass news to the view and inside the view pass it to the 'news' view.
Because news are going to be on roughly 70% of pages, I would like for this system to work (I want to use other views in such fashion). Is this possible?
Upvotes: 0
Views: 61
Reputation: 3098
You can check the Codeigniter HMVC extension:
This is most useful when you need to load a view and its data within a view. Think about adding a shopping cart to a page. The shopping cart needs its own controller which may call a model to get cart data. Then the controller needs to load the data into a view. So instead of the main controller handling the page and the shopping cart, the shopping cart MVC can be loaded directly in the page. The main controller doesn’t need to know about it, and is totally isolated from it. You can work the same way with your news
block.
I think it's a little bit tricky to try to explain everything on a simple SO answer and it has good documentation you can check out there.
Upvotes: 1