Welcome Guest, Not a member yet? Register   Sign In
Code Structure
#1

[eluser]Unknown[/eluser]
I'm relatively new to using CI so I have a question on what is the best way to structure my code for modularity while still using MVC pattern. I understand the basics of the MVC pattern. The problem I'm running into is as follows.

My model handles database access and insertion. My controller interfaces with the model to get information from the database and sends it to the view. My view handles displaying the information recieved from the database.

This works fine until I start putting multiple things on a page. I'll have the page content first. I want to have "related items" after the actual content however. I can write out more code in each controller to fetch the related items from the appropriate model and display it using the appropriate view. The problem then becomes I want the related content on a number of different pages (with articles, with videos, with pictures, etc..) so I end up duplicating the code 10 or more times identically in each controller.

If I wasn't using the MVC pattern I could integrate my model/controller code in one PHP file and just include it in 10 places. Sticking to the MVC framework that doesn't work. The bulk of the work might be done in the model but I still need a few extra lines of code for every controller. If I decide to make changes later I could easily break the application if I only changed 9 of the 10 sets of code...

I'm not entirely sure how you solve this problem. If I could include other controllers inside a controller that would do it but I haven't been able to figure out how to do that. If anyone has any suggestions for tackling this problem let me know.
#2

[eluser]Zack Kitzmiller[/eluser]
Write a library.




Theme © iAndrew 2016 - Forum software by © MyBB