You inquire about the suitability of creating general bundles, such as FrontendBundle and BackendBundle, to hold code shared by both the frontend and backend. While this approach can be justified, it is generally not considered best practice.
Instead of using separate bundles for general features, consider creating a CommonBundle. This bundle would house components that are utilized by multiple bundles, such as:
You mention concerns about the location of layouts. The Symfony best practices recommend against placing layouts in bundles. Instead, it is preferred to store them in the app/Resources/views/ directory. This centralizes their management and simplifies template inheritance.
You propose a RootBundle to contain all app-specific code. While this is a viable option, it can lead to a large, unwieldy bundle. A better approach is to create dedicated bundles for specific functionalities, such as:
These dedicated bundles allow for cleaner code organization and easier reuse across multiple projects.
The optimal bundle structure for a Symfony2 application depends on the specific requirements. However, following the best practices outlined above can help improve code organization, maintainability, and reusability.
The above is the detailed content of When to Use General Bundles vs. Specific Bundles in Symfony2?. For more information, please follow other related articles on the PHP Chinese website!