A
A
alex5e2018-05-27 17:46:07
symfony
alex5e, 2018-05-27 17:46:07

How to create Bundles in Symfony 4?

How to create a reusable bundle in Symfony 4? Best practices for Symfony 4 do not recommend creating bundles inside your application, and the generate:bundle command has been removed from the console

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
voronkovich, 2018-05-27
@alex5e

1. Create a directory for bundles (for example, bundles as suggested by Maxim Fedorov )
2. Create a directory for the bundle. For example, bundles/AcmeBundle
3. In composer.json add:

"autoload": {
    "psr-4": {
        "App\\": "src/",
        "AcmeBundle\\": "bundles/AcmeBundle/"
    },
}

4. In the bundle directory, create its class:
<?php

namespace AcmeBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeBundle extends Bundle
{
}

5. Register the bundle in the config/bundles.php file:
return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    AcmeBundle\AcmeBundle::class => ['all' => true],
];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question