For my application bundle, I will need some classes that are neither controllers nor models. For instance, I would like to have a scorecard
class that has members such as "skill", "efficiency", "beauty", etc. Also, it may have member method/getters like "meanScore".
Where would such a class go in the Symfony framework?
I agree with @Gordon that this sounds like a business object. But if you're sure that it isn't, your next step is to figure out how you would classify it. Is it a helper? An event listener? A utility class? Once you figure that out, ask yourself: is it specific to a bundle, or are you going to reuse it amongst projects?
Let's say you decide it's an event listener and belongs to the bundle. Put it in MyBundle/EventListener
. If it's a helper, put it in MyBundle/Helper
. Now if you plan on reusing it amonst projects (which in this case it actually doesn't sound like it, but bear with me...) you might be better off creating a place in vendor
for it.
The important thing to remember is that because Symfony2 is so young, there isn't really a definitive list of best practices that answer questions like these. Right now it's kind of up to us to see what works, and what doesn't. It's like the wild west :)
The way I answer these sorts of questions for myself is I go to KnpBundles and check how other developers are doing it.
Another thing to note is that Symfony2 is all about freedom of choice when it comes to configuration. You can stick everything in Random
folder for all Symfony2 kernel cares, as long as you set it up correctly. Well, that's probably taking it a bit to the extreme, but for example Listener
or EventListener
- no difference.
Now, if you'd ask me, I'd say that for the Scorecard
- depending on where you're going to use it, either Service
or Helper/Util
About the breadcrumb
- seems like a good example for a twig extension.
Since this class apparently represents a business object from your Domain, it belongs to the Model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With