I want to separate my sections in Symfony by folders like this:
src
- Blog
-- Controller
-- Entity
-- Form
-- Repository
- Main
-- Controller
-- Entity
-- Form
-- Repository
With bundle I can't use annotation in controller and entity and I can't use make:entity in my blog separately. Is there any way to create this structure in symfony 4?
As Symfony is a PHP framework and doesn't impose any choices, you're free to place your classes anywhere you like as long as the Composer autoloader is able to load them. You might have to configure packages to look for objects in other namespaces/places as well. They are by default configured in your application to be loaded from the predefined file structure.
For instance, when your entity lives in
src/Blog/Entity/Post
, it should probably have the fully-qualified class name likeApp\Blog\Entity\Post
. You then have to tweak the default Doctrine configuration to load entities with such namespace:Another example, you have to change the routing configuration so that it looks for controllers in
App\Blog\Controller
: