The release of the popular framework's 4th version was marked by a capital changes in the structure for projects. Including the official documentation notes the following regarding the code bundling (http://symfony.com/doc/current/bundles.html):
In Symfony versions prior to 4.0, it was recommended to organize your own application code using bundles. This is no longer recommended and bundles should only be used to share code and features between multiple applications.
In the 2nd and 3rd versions, the bundle performed two main tasks. 1) If the developer or a group of developers in their different projects used one large repetitive functional, then it could be taken out in a separate bundle and transferred from the project to the project. A good example of such use is a system of users in any project. It includes the models of User, Role, Permission (and possibly others), controllers for entity, plus controllers for signing in the app, signing out the app (the security policy may be different at the same time), and templates for view. Another good example is the administrative panel, the foundation for which is identical. 2) Symfony took separate functionality in different directories from the logic point of view and, accordingly, namespaces by bundling. For example, on one of my past projects, I divided the spaces: user management system, application gamification (social network goal), partner space, geo-environment (for working with maps and defining cities by IP), an environment for payment transactions. As follows.
In my next project I do not want to use anything other than Symfony4 to follow the best practices of the framework during the implementation of its new features. How can I organize the separation of logically independent code in different areas, if the official documentation no longer insists on the creation of bundles??? If all the classes of the model are stored in the same directory, this creates confusion and increases the time to find the desired file in the structure of a large project. The same applies to templates and indeed everything else. When I work with one functional, I have only dropdowned directories of this functionality.
Is it now that Symfony encourages you to define the structure of classes, templates and the like at your own discretion?
Being new to Symfony and starting with Version 4.2, I had the same problem as @DeveloperMobile.
This is my Directory Structure based on the recommendations from the Guide Symfony Best Practices Version 4.2
The recommendation basically says about the structure:
So basically it says: Yes, you can organize your Code in /src with Subfolders, but Code with a Certain Functionality, like Controller, Entity, Form, Repository, etc. should be in the specific Directory.
root/
├─ assets/
├─ bin/
│ └─ console
├─ config/
└─ public/
│ └─ index.php
├─ src/
├─ Controller/
├─ DefaultController.php
├─ ...
├─ Api/
│ ├─ ..
│ └─ ..
├─ Backend/
│ ├─ ..
│ └─ ..
├─ Entity/
├─ Form/
├─ Repository/
├─ Twig/
├─ Utils/
└─ Kernel.php
├─ tests/
├─ templates/
├─ translations/
├─ var/
│ ├─ cache/
│ └─ log/
└─ vendor/
This is the List of all recommendations from the Link above:
Don't create any bundle to organize your application logic.
(Symfony applications can still use third-party bundles (installed in vendor/ ) to add features, but you should use PHP namespaces instead of bundles to organize your own code.)
Define the infrastructure-related configuration options as environment variables. During development, use the .env and .env.local files at the root of your project to set these.
Define all your application's env vars in the .env file
For most projects, you should store all your code inside the src/ directory. Inside here, you can create whatever directories you want to organize things:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With