Where do I put classes in symfony that are neither controllers nor models?

For my application package, I will need some classes that are neither controllers nor models. For example, I would like to have a scorecard class that has elements such as “skill”, “efficiency”, “beauty”, etc. Alternatively, it may have a member method / getters as "meanScore".

Where would this class fall within the scope of Symfony?

+8
php model-view-controller symfony
source share
3 answers

I agree with @Gordon that this sounds like a business entity. But if you are sure that this is not the case, your next step is to find out how you classify it. Is this an assistant? Event listener? Utility class? As soon as you find out, ask yourself: is this specific to the package, or are you going to reuse it among projects?

Suppose you decide that this is an event listener and belongs to a set. Put it in MyBundle/EventListener . If it's an assistant, put it in MyBundle/Helper . Now, if you are planning to reuse his ammon projects (which in this case are not really like him but carry me ...), you might be better off creating a place in vendor for him.

It’s important to remember that since Symfony2 is so young, there is really no definitive list of best practices that answer such questions. Right now it's up to us to see what works and what doesn't. It's like a wild west :)

+8
source share

As I answer these questions for myself, I go to KnpBundles and check how other developers do it.

Another point - Symfony2 is freedom of choice when it comes to configuration. You can paste everything into the Random folder for all the worries of the Symfony2 kernel, if you configured it correctly. Well, perhaps this is a bit extreme, but, for example, Listener or EventListener - no difference.

Now, if you ask me, I would say that for Scorecard , depending on where you are going to use it, either Service or Helper/Util

About breadcrumb - seems like a good example of branch expansion.

+3
source share

Since this class seems to represent a business object from your domain, it belongs to the model.

+2
source share

All Articles