Dawid Ohia
Dawid Ohia

Reputation: 16445

How to pick a name for a controller in Symfony2?

For starters let me say that I know that the name of the controller should ends with Controller to fit nicely into the framework. But I would like to know what do you usually put before the Controller part?

For example, in unit tests it is quite straightforward, before Test you put the name of the class which you want to test. So in Symfony2 I should put the name of the entity which is the central object of interest in this controller? Maybe there are different approaches? I am interested in your experience, do you stumble across some pros or cons while taking one or other path? Or maybe "it doesn't matter"?

Upvotes: 0

Views: 1422

Answers (1)

Nanocom
Nanocom

Reputation: 3726

You can name your controller as you wish, and there is no real convention about that.

  • I usually call my controller with the name of the main entity that it deals with. For example, if I have a NewsBundle with entities News and Comment, I call my controller NewsController (even if I manipulate comments in it).
  • If I have only one controller in my bundle, I name it with the name of the bundle.
  • You can have several "modules" inside a bundle, you usually have one controller for each "module": example with FOSUserBundle: they have modules Security, Resetting, Registration, etc. Each of these modules have a dedicated controller and folder in the Resources/views folder.

Upvotes: 3

Related Questions