如何使用 Symfony 1.4 避免大型操作类
目前正在处理一个项目,但感觉代码的结构/解耦/可维护性不够好。
我认为主要问题是使用一个操作类来完成系统的主要工作。但还有什么选择呢?我的其他模块非常基本且独立。
如果模型包含更多我在控制器中拥有的业务逻辑(此时相关操作类的模型文件或多或少是空的,表模型文件也没有太多)。
我正在阅读 http://www.slideshare.net/nperriault/30-symfony-最佳实践有一些优点,其中之一是避免使用大型操作类,但并没有真正告诉您应该如何完成。
我是否应该分解我的动作类并在 /apps/frontend/module/myModule/lib/ 中有不同的文件。 ?
问题是我有另一个动作类,它必须重用上面提到的类中的一些功能......我真的不想有重复的代码,并且会陷入一些混乱。
一些一般性的指示会很好,谢谢
working on a project at the minute and don't feel the code is as well structured/decoupled/maintainable as it should be.
I think the main problem is using one actions class to do the brunt of the work of my system. But what are the alternatives? My other modules are pretty basic and separate.
Should the model contain more business logic that I have in my controller (at the minute the model file for the actions class in question is more or less empty, the Table model file doesn't have much either).
I was reading http://www.slideshare.net/nperriault/30-symfony-best-practices which has some good points, one of them being avoiding having large actions classes but doesn't really tell you how it should be done.
Should I break up my actions class and have different files in /apps/frontend/module/myModule/lib/. ?
The problem is I have another actions class that has to reuse some functionality from the class mentioned above... I really don't want to have duplicate code an am getting into a bit of a mess.
Some general pointers would be great, thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将所有操作保存在一个文件中,也可以将每个操作放入其自己的文件中。
所以,或者
或者
加上
这一切都是 在文档中。然后,您应该将可重用代码放入两个操作类都可以扩展的父
XYZAction
类中。You can either keep all actions in one file, or put each action in its own file.
So, either
or
plus
It's all in the documentation. You should then put reusable code in a parent
XYZAction
class that both action classes can extend.您始终可以将代码放入
apps/frontend/lib
中。创建具有可重复使用的代码的类,您只需从操作中调用方法即可避免重复You can always put code in
apps/frontend/lib
. Create classes that have the code that may be re-used and you can just call the methods from within your actions to avoid duplication