Symfony2 Conceptual Conundrum: General Bundles vs. Specific Bundles
Navigating Bundle Structure
Creating bundles for generic sections of an application, such as frontend and backend, can raise concerns. While it's possible, it's not the most recommended practice. Instead, consider including both frontend and backend functionalities within the same bundles.
Location of Layouts
The recommended location for layouts is not the app/Resources/views/ directory but rather within the Resources/views directory of the specific bundles. This allows for cleaner organization and easier maintenance.
Managing Common Code
For code shared by multiple bundles, the CommonBundle is a suitable option. It eliminates the need for excessive bundle creation and ambiguous decision-making. Additionally, CommonBundle can house reusable elements like CSS, images, and common views.
App-Specific Bundles
Contrary to past approaches, it's now advised to have only one app-specific bundle named AppBundle. This simplifies development, eliminates unnecessary complexity, and ensures interdependency among bundles. App-specific bundles may contain both entities and non-Symfony2-specific components.
Subnamespaces and Reusability
Utilizing subnamespaces within bundles offers logical partitioning without resorting to excessive bundle creation. If code within AppBundle becomes reusable, it can be extracted and packaged as an independent vendor-installed bundle.
The above is the detailed content of What are the Best Practices for Bundling in Symfony2 to Avoid Redundant Creation and Ensure Clean Organization?. For more information, please follow other related articles on the PHP Chinese website!