Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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:)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top