Search code examples
symfonysymfony-2.1symfony-sonatasonata-admin

Organise files in SonataAdminBundle: what goes where?


I have regrouped the following information from a few examples in the SonataAdminBundle documentation. Please correct me if there are some errors, but here is what I get in the case of a BlogBundle:

Frontend and Backend files are mixed in the same bundle

As you can see, in general, each bundle contains both frontend and backend classes.

It seems very messy to mix both frontend and backend in the same folders somtetimes (see Controllers), but to be honest I can't think of an other way...

I actually started handling backend in a separate bundle but then realised that it was also too messy.

So in practice, do people really follow this architecture? Is this the only/best way to handle backend when using SonataAdminBundle?

This beautiful post here is using a different approach...any ideas what I should do to make sure the code doesn't get too messy.


Solution

  • Simple: use folders within locations of mixed content. I put frontend components directly in their respective folders, and add Admin folders for backend files.

    You can refer to e.g. a controller in the Admin subfolder like this BlogBundle:Admin\Concert:index, essentially the same works for templates.

    On configuration, you could create a config-frontend.yml and a config-backend.yml file, then include it in the original config.yml file. I don't do that though.