Reputation: 79796
if i've got a thread model and controller.
should that be in singular or plural for both the model and controller?
i could show a thread and also list threads.
dont know what i should use.
$thread->get_lists(); // doesnt sound good
$threads->show(); // doesnt sound good
Upvotes: 14
Views: 12270
Reputation: 3358
for name of table database, use plural example = "users"
for name of controller, use singular and capital example = "User_Controller"
Upvotes: 0
Reputation: 705
I know that this is an old question, however I recently had a long debate with my co-workers about this.
While personally I prefer singular for controllers and at the same time absolutely think that singular/plural should not matter / enforced ...
Most of the well known APIs out there are using plural for controllers. This is an argument that has very strong potential to end the debate
For example Twitter API Google plus API
Upvotes: 1
Reputation: 1057
That depends on the model. If objects of that class represent exactly one thing, use singular, if they represent many things, use plural (but you usually do not need such a class, use an array/a collection). Both cannot happen or you should redesign (1).
I'll use your Thread example:
If every object models one thread, name the class "Thread". If it models several threads at once, call it "Threads" (or "ThreadCollection" or the like).
(1) If you need both, a representation of a single thread and a representation of many threads at once, use two distinct classes (Thread and Threads) or create an array or a collection for the latter. Then you'll have it clean: $thread->show(); $threads->list();
Upvotes: 4
Reputation: 317129
Like the others said, it doesn't matter.
Concerning models, I like to use singular when the class represents a single row, e.g. when using Active Record or Table Row Gateway and plural when working with classes representing tables and recordsets, simply because I could make these return or contain classes with singular names and I could distinguish between them. But then again, I could just as well name them UserTable, UserCollection and User. Use what best represents your domain.
Some frameworks have a convention for naming models and controllers to work some automagic. For instance, the singular models will be inflected to use plural tables by default, so you do not have to map it yourself. This is called convention over configuration; over, because usually you can still configure it as you see fit.
The only time when I'd say it doesn't matter how you name your models and controller is when a code convention in use.
Upvotes: 2
Reputation: 1419
KohanaPHP handles their singular/plural MVC components very well. I would check it out for reference as it makes sense. But when it comes down to it, it really doesn't matter and it depends on the programmer. I mean, if you are getting a bunch of lists, do get_lists() or if your getting contents of a list use get_list().
Upvotes: 2
Reputation: 29301
It doesn't matter.
I personally use singular for models and plural for controllers.
What matters, however, is that you pick a scheme and be consistent.
Upvotes: 19