Currently, I’m using CodeIgniter framework for my web applications and I have faced one tricky point in my app design and I wanted to know, what is a good approach(es) to solve it.
I have 3 different objects (controllers) that could have comments. I was curious, since it is a common functionality for all of these 3 objects (read comments, write a comment, etc). So my question is: how it should be designed ? (Where to put all the common controller methods and how to handle a model methods). What is the right MVC approach for it ? How to keep it DRY ?
I guess you’ve read Phil’s blog post, then = ).
If you want to share logic among the other controllers, you could probably just create a comments library, a comments model and load it for each of the other classes.
Codeigniter Libraries
As for your database, if you wanted to store all comments in one place, you could probably do something like this:
comment_id
comment_text
comment_relation
comment_relationId
…Where relation and relation id would reference another table and some particular piece of content.
I think this would be a good approach.