0

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?

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116

2 Answers2

3

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.

Aman Varshney
  • 820
  • 1
  • 9
  • 26
  • So what would the model folder be? `src`, `Entity`? What would you suggest? – Gottlieb Notschnabel Aug 15 '13 at 09:59
  • Its really up to you. Many bundles out there simply create a Model directory at the root of the bundle. – d0001 Aug 15 '13 at 10:38
  • If I move my `Class.php` from `MyBundle\Entity` to e.g. `MyBundle\Resources\src` it says it cannot find the class. I set `namespace Acme\MyBundle\Entity` to `namespace Acme\MyBundle\Classes` and used it via `use Acme\MyBundle\Classes\MyClass` but it won't work :( – Gottlieb Notschnabel Aug 15 '13 at 12:11
  • Define a Model directory then in the Entity directory define the entities and extend from your model classes. Since you are extending from a model class best way is to use XML or YML for metadata(mapping). If you want to use Annotations you will have to override the properties which, in my opinion, defeats the purpose of extending from a Model class. – d0001 Aug 19 '13 at 06:18
1

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

Epok
  • 661
  • 1
  • 8
  • 16