I created a bundle in Symfony2 that contains my webapp. In there I have some Entities that are mapped to my MySQL-Database. They are located in Acme\MyBundle\Entities.

Now I have created some helper classes that I will not just use in MyBundle, so I outsourced them into a separate bundle (e.g. Acme\MyHelperBundle). Everything is clear until here.

But where exactly do I put business logic files? Do I put them into

  • Acme\MyHelperBundle\Entities or
  • Acme\MyHelperBundle\Resources or
  • Acme\MyHelperBundle\Resources\src
  • or any other location?

And what would be a good namespace for these helper classes?

有帮助吗?

解决方案

create a model folder and in that make a class where you put the business logic and create a service of that class and used that classes anywhere in the project.

其他提示

I think there's no real rules for that. if your helper class are declared as services (i think so if you want to use them in all your bundle) you can create a Manager folder. So when i'm on a bundle and there is a Manager, i know that i have some logic that i can reuse everywhere.

It's depend, too, on what you put i your files, but if it's some helper like a UserManager.php on which you create some new request (And you declare it as a service), the Manager folder it's a good place to start.

You can find this folder Manager in many bundle like fosElasticaBundle

ps: sorry for my english, i hope it's clear enough:)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top