1

I'm starting to develop a project that will be quite big (hear lots of files) and I want to have an organization that's different from Symfony's default one: instead of having one dir for all my controllers, another for all my forms, etc, I want to have one dir per functionality, ie a directory for my homepage which will contain the controller, the templates, another dir for the blog page with the controller, forms and templates, and so on.

I tried what was explained in this (old) answer, and it didn't work : my routes weren't recognized, and a php bin/console debug:router showed they weren't listed anymore.

I feel I will have something to adapt in my routes.yaml file, which looks like this for now, and which explains why it doesn't work because it explicitely searches in the src\Controller directory:

controllers:
    resource:
        path: ../src/Controller/
        namespace: App\Controller
    type: attribute

I looked in the documentation I found, but I didn't find anything useful (I think I will have to remove the path and change it to something else, but I don't know what yet.

Marc Brillault
  • 1,902
  • 4
  • 21
  • 41
  • I'm guessing you tried to use attributes for routing with the linked answer? Not going to work. The linked answer just tells Symfony the classes are controllers. If you want controllers to be placed anywhere then explicitly define your routes using one or more route files. You may find this to be easier than using attributes regardless. If you want to limit your controllers to a fairly small number of directories then of course you can just add a some additional attribute directories in your routing file. – Cerad Feb 20 '23 at 00:35

1 Answers1

0

The above solutions are only for differentiating controller and template files. But For Entity, Events, and Forms it will not work.

It seems like you want to separate files for each module or functionality. For example, settings.yaml, controller, entity, forms, events, etc...

For that Symfony provides a Bundle feature. You can create a new Bundle in Symfony and use it as a separate feature. For more details please read this link

Bhavin Nakrani
  • 442
  • 3
  • 12
  • Entity mappings work fine with multiple directories though you do need a tiny bit more configuration. Events and Forms? Nothing special at all about those. Put them wherever you want. – Cerad Feb 20 '23 at 20:49