Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 where to place custom helper classes

Tags:

symfony

I'm starting with a Symfony2 project. I know the framework basics but I have a question: Where is the right place to pot those helper classes I create for help or for the business logic?

like image 363
acanimal Avatar asked Mar 18 '12 14:03

acanimal


2 Answers

Max's answer is correct. However I question the path he recommends for your code.

The following classes and files have specific emplacements:

Service Container Extensions (belong in) DependencyInjection/

from http://symfony.com/doc/current/cookbook/bundles/best_practices.html

That says your Services should be placed in a folder called 'DependencyInjection', not 'Services'. In full, it should be src/Foo/BarBundle/DependencyInjection

I say this as someone that had the former and has just finished moving them all to the latter (!)

like image 124
Adam Knowles Avatar answered Sep 20 '22 12:09

Adam Knowles


What @Adam says is wrong, you have to store your Dependency Injection Extensions in DependecyInjection directory, not the services itself. In the documentation says that you can store your (custom) business logic classes in any place you like.

http://symfony.com/doc/current/best_practices/business-logic.html

like image 34
PachinSV Avatar answered Sep 21 '22 12:09

PachinSV