musicman
musicman

Reputation: 525

Symfony: Relation between Bundles and Services

I'm planning to write an AJAX extension for the forms in Symfony3. I want to be able to use ajax requests in many forms instead of submissions.

Now I don't understand the exact relation between Bundles and Services.

As I understand it to write a service is the right way to do so. At the same time I want to make my code reusable, so I can use it in further projects. My extension needs to have some JS and TWIGs I guess.

So, is the right way for deploying my service to encapsulate in a bundle? Or are they bundles theirself? Or can they be deployed without encapsulating?

Upvotes: 1

Views: 133

Answers (1)

Renato Mefi
Renato Mefi

Reputation: 2171

If you want to make your code reusable, you need to make your bundle configurable, basic steps to achieve it:

  1. Create a bundle: http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html

  2. Making it configurable: http://symfony.com/doc/current/cookbook/bundles/configuration.html

  3. You need to put it in another repository and read it later using git submodule or packagist, depending on your strategy or if its private or not.

This steps will means your bundle cannot depend of any class internally created in your project, I would recommend to you to check some other bundles around. A good example can be the Tactitian bundle, which integrates the League Pipeline library into SF https://github.com/thephpleague/tactician-bundle In this code you can see how they configure the library and create the services around it!

I hope this helps you!

Upvotes: 2

Related Questions