Help with organising directory structure

Silverstripe Version: 4.1

I renamed the code directory to src.

Now everything is in this one directory and it’s a little messy.

If possible, how can I arrange it so I can have some child directories in there, at least:

/controllers
/models

And still have it all work?

Hi,

you can just create what ever directory structure you like in your src folder and move your php files to those sub directories. After doing that, just run dev/build?flush=all in your browser to make SilverStripe to rescan your php files.

That should do it :).

You can also namespace your php classes so that they contain the sub folder names that you just created, but SilverStripe doesn’t require this. It’s just a cleaner way to do namespacing especially in bigger projects. It just helps you to find the class file location if you see the class name + namespace referenced in another location.

1 Like

As @Taitava says, you can order your files in any structure within /src. Generally I tend to use the following structure:

  • model (all model classes)
  • control (all controller classes)
  • extensions (all extension classes)
  • helpers (helper/utility classes that are used by several other classes and don’t fit the above)

You can also add sub folders within these, so for example you could also have: /src/control/cms (for all PageController classes).

1 Like

@Taitava @PsychoMo

Thank you!