symfony-docs
symfony-docs copied to clipboard
Inconsistent documentation regarding bundle directory structure
There is an inconsistency between best practices and bundles documentation regarding the directory structure
https://symfony.com/doc/5.4/bundles/best_practices.html#directory-structure
<your-bundle>/
├── config/
├── docs/
│ └─ index.md
├── public/
├── src/
│ ├── Controller/
│ ├── DependencyInjection/
│ └── AcmeBlogBundle.php
├── templates/
├── tests/
├── translations/
├── LICENSE
└── README.md
https://symfony.com/doc/current/bundles.html#bundle-directory-structure
I would LOVE to use the new directory structure, get rid of the Resources level directory and use config, templates and public, just like the main application. But I've never been able to get that to work. If there's a setting somewhere to use the Best Practices directory structure (skip the /Resources), can that be documented?
I think we need to update the second article to match the structure of the best practices article.
I would LOVE to use the new directory structure, get rid of the Resources level directory and use config, templates and public, just like the main application. But I've never been able to get that to work. If there's a setting somewhere to use the Best Practices directory structure (skip the /Resources), can that be documented?
You need Symfony 5 for the new structure to work. Also, you need to edit Bundle::getPath()
and probably also the path in Extension::load()
. https://github.com/symfony/symfony/blob/5.4/UPGRADE-5.0.md#httpkernel
Thanks, this is almost working for me now. I'm not sure how to reference the bundles when loading routes, though, as it fails with the new structure.
# /config/routes/my_bundle_base.yaml
my_company_base_bundle_oauth:
resource: '@MyCompanyBaseBundle/Controller/OAuthController.php'
prefix: /
type: annotation
Curiously, the src/Controller directory didn't move (unlike views=>templates and config). Services seem normal (and work with the "traditional" bundle structure.
<service id="MyCompany\BaseBundle\Controller\OAuthController" public="true" autowire="true">
<tag name="container.service_subscriber" />
<tag name="controller.service_arguments" />
</service>
Is there a way to list the path resources? I'm trying to follow the FileLoader and YamlFileLoader, but having trouble figuring out where the map comes from to get from @whatever to an realPath.
Can anyone point me to a bundle that uses the best practices and the new directory structure? I'm really having a hard time trying to figure out how to reference the controller path. @weaverryan , do you think you'll update your excellent SymfonyCast tutorial on how to make a reusable bundle? Especially now that recipes are now much easier to publish since Flex is serverless. (At least that's how I'm readying it.)
Thx.
@tacman Most of Symfony bundle use this structure.
But some "offical" bundles use a mixed directory structure :
- https://github.com/EasyCorp/EasyAdminBundle
- https://github.com/symfony/panther
There is a src/
and assets/
folder but config, templates and translations are in src/Resources
folder.
I my repository, there is 2 bundles that uses the best practises structure.
What is the consensus for new bundles structure? I like the way https://github.com/symfony/panther is structured.
https://github.com/symfony/mercure-bundle or https://github.com/symfony/webpack-encore-bundle also use "src/", I feel it's the new convention, it would be great to have the documentation reflect it.
Hello, I'm trying to figure out the right directory structure of a bundle (for 5.4).
Is there finally a consensus, the PR is still not merged ? Thanks
Unfortunately it didn't move, I personally went for https://symfony.com/doc/current/bundles/best_practices.html#directory-structure because I prefer to have my sources in src/
and configs/readme/etc. outside
I agree with you about src/ & config/ folders.
Thank you for your reply :+1:
Some new UX bundles are also using the src/
folder (eg. https://github.com/symfony/ux/tree/2.x/src/Autocomplete) and some not (eg. https://github.com/symfony/ux/tree/2.x/src/Chartjs). I'm not sure why it's not consistent across the same repo.
Yea, we should normalize that - someone else started with some packages NOT using src/
, but I HAVE used src/
for the packages that I've created.
I created an issue to track this @weaverryan. And I didn't realized but the docs got updated 4 months ago in https://github.com/symfony/symfony-docs/pull/16801, both pages now use src/
for the logic!
We can probably close this issue.
I also think we can close this issue