# Bundles ## How to Create a bundle First we are going to get the bundle functioning in an existing project, then move it to composer/packigst. ### Create files and directories Example: ```bash newdirs='lib/ContactForm/src' mkdir -p ${newdirs}/Controller ${newdirs}/Controller ${newdirs}/Entity ${newdirs}/Repoository ${newdirs}/DependencyInjection touch ${newdirs}/Controller/ContactFormController.php touch ${newdirs}/ContactForm.php touch ${newdirs}/Controller/ContactForm.php ``` The ContactFormController.php example: ```php render('@SymfonyCMS/dashboard.html.twig', [ 'controller_name' => 'ContactFormController', ]); } } ``` You will have to make changes to namespace, classname, route, render. The ContactForm.php file example: ```php ['all' => true],``` composer would do this automatically if it was grabbing from packigst, but we are just using a dev environment for now. Example: ```php NickYeoman\ContactForm\ContactForm::class => ['all' => true], ``` ### Symfony Bundle Config Create a DependencyInjection file: ```php load('services.yaml'); } } ``` Next create a service in config/services.yaml: ```yaml services: NickYeoman\ContactForm\Controller\: resource: '../src/Controller/' tags: ['controller.service_arguments'] ``` Finally, you can specify the route. Create a new route file config/routes.yaml ```yaml ContactForm: resource: path: ../src/Controller/ namespace: NickYeoman\ContactForm\Controller type: attribute ``` ## Resources * [Official Symfony Docs - Create a bundle](https://symfony.com/doc/current/bundles.html#creating-a-bundle) * [Symfony casts - Bootstrapping](https://symfonycasts.com/screencast/symfony-bundle/bundle-directory)