我在哪里将既不是控制器又不是模型的类放在Symfony中? [英] Where do I put classes in Symfony that are neither Controllers nor models?
问题描述
对于我的应用程序捆绑包,我将需要一些既不是控制器也不是模型的类.例如,我想要一个scorecard
类,该类具有诸如技能",效率",美容"等成员.此外,它可能具有诸如"meanScore"之类的成员方法/获取器.
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".
这样的类在Symfony框架中会放在哪里?
Where would such a class go in the Symfony framework?
推荐答案
我同意@Gordon的话,这听起来像是一个业务对象.但是,如果确定不是,那么下一步就是弄清楚如何对其进行分类.是帮手吗?事件监听器?实用程序类?一旦弄清楚了,问问自己:它是特定于捆绑软件的,还是要在项目中重用?
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?
比方说,您确定它是一个事件侦听器,并且属于捆绑包.将其放在MyBundle/EventListener
中.如果是帮助者,请将其放在MyBundle/Helper
中.现在,如果您打算在其他项目中重用它(在这种情况下,它实际上听起来并不像它,但请忍受...),您可能最好在vendor
中为其创建位置.
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.
要记住的重要一点是,由于Symfony2太年轻了,因此实际上并没有确定答案的最佳实践的确切清单.现在,由我们来决定什么有效,什么无效.就像狂野的西部:)
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 :)
这篇关于我在哪里将既不是控制器又不是模型的类放在Symfony中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!