douchui1657 2015-11-20 10:05
浏览 63
已采纳

捆绑Symfony 2项目中的特征位置

I have a design doubt about Symfony 2. The fact is I want to use a trait into a bundle of mine but I am not sure where to locate the trait. It is not a controller, it is not a model or entity.

I have a solutions on mind but I am not sure if it follows the best practice. The idea is create a new folder called /Trait. It is correct?

<your-bundle>/
├─ AcmeBlogBundle.php
├─ Controller/
├─ Entity/
├─ Trait/ <- My thought
├─ README.md
├─ LICENSE
├─ Resources/
│   ├─ config/
│   ├─ doc/
│   │  └─ index.rst
│   ├─ translations/
│   ├─ views/
│   └─ public/
└─ Tests/

Thank you very much

  • 写回答

1条回答 默认 最新

  • duandao1931 2015-11-20 13:38
    关注

    You can't use Trait, since it's a php keyword, so you'll have to use Traits, but apart from that, your suggestion is fine.

    Bundle structure is only there for your convenience, it shouldn't be something limiting you, feel free to create any namespaces as you like. In fact you can use Symfony without bundles at all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?