开发者

pro/con of having single/multiple action per file in symfony?

开发者 https://www.devze.com 2022-12-27 01:31 出处:网络
been working with symfony for a while. most tutorials describe having multiple actions in a single php file. however, i find having 1 action per php file easier to maintain.

been working with symfony for a while. most tutorials describe having multiple actions in a single php file. however, i find having 1 action per php file easier to maintain.

  • what's the pro/con of both?
  • is this purely a developer preference in code organisation?
  • any performance impact on either approach?
  • what's common 开发者_StackOverflowpractice for reasonably large production applications?


Being an amateur symfony developer myself and having worked with more experienced symfony devs, my impression is that this is largely dependent on both what best suits the application AND your preference to organising the code. Once you start working on a more complex application, these kinds of questions answer themselves to some extent, as you will begin to notice how the organisation of your projects affects the ease of working with it.

On a site I'm building currently, I have about 20 modules, with:

  • modules that have single action & template pairs
  • modules that have single actions serving multiple templates
  • modules that have multiple actions serving multiple templates

In total, there are probably 40-50 actions.

Apart from organising your code in relation to your models, the module structure also has significance in relation to the Symfony configuration cascade. Because layouts and configuration files such as view.yml, security.yml, etc are most easily set at app & module levels, good structure helps you take advantage of the cascade in a straightforward way. The same applies to routing rules, depending on how you use these on your site.

I don't have enough insight to comment on performance -- perhaps someone else here does. Would be interested in hearing about that myself.


I work for a small shop [3 programmers] and we've used both approaches on different projects as well as mixed them together on the same project. If we're working on a project that needs all 3 of us working on the same action, having one action per file is the saner way to deal with things [why put yourself through managing svn file conflicts when you don't have to].

I've worked on bigger projects alone, and I almost always go with multiple actions in one file. With a good IDE, it doesn't matter as much because you can expand/collapse the action you're working on and my guess is that the performance difference is negligible [I might be wrong].

Some other things like preExecute() and sharing functions also seem to be easier when you have all your actions in one file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号