I’ve started using CodeIgniter and I seem to be doing pretty well. I’ve hit an issue though.
I have a controller called Articles. Users of the site can do the following:
- Get an article by slug name
- Get a list of articles in a category
- Get a list of articles that have x tag name
My issue is should I create 3 separate controllers:
Article.php– For single articlesCategory.php– For list of articles that have x categoryTag.php– For list of articles that have x tags
Or, should I place everything in Article.php?
I’m just trying to figure out the conventional way of doing things.
It’s up to you (of course), but it sounds like you want one controller, as long as Tags and Categories mean nothing by themselves, without Articles.
For semantics sake, I would rename it to
Articles.phpwith the “s”. Then you will have:Where “category” is a method of the class/controller
Articles. Just remember to change your controller class name as well.I would probably rename the “tags” method to “tagged”, similar to what Stack Overflow does, so the url makes a little more sense:
Similar to:
For individual articles, create a method called “view”:
If “Tags” or “Categories” were standalone entities or can house more things than just Articles, you might want to make them each their own controller, but in this case I don’t think you need to.