3
votes

I want to create a blogging system in order to practice symfony2, but currently I get a bit confused when creating entities such as user or blog. The reason is the following :

  • User( or Blog) is commonly used in frontend and backend(admin) (currently I have considered creating FrontendBundle and AdminBundle)
  • Entity must belong to one bundle.

Currently I have considered the following methods, but what is the best way in this case, or please tell me if there is another way.

  • Create bundle named 'BlogCommonBundle' and define User entity as "BlogCommonBundle:User".
  • Define all controllers under 1 bundle, such as 'BlogBundle', so frontend/backend(admin) controllers belong to same bundle.
2
Why not create an additional UserBundle and make Frontend and Admin dependant on it?hakre
Thank @hakre for your answer, and I'm sorry for my response was slow, I did not noticed your comment. I had not considered the pattern which you advised at that time. But as Arms advised below, it's new idea for me.tristar

2 Answers

3
votes

I think creating a BlogBundle and having multiple controllers for frontend and admin functionality is a good way to handle this. Both controllers would make use of the same entities and repositories, and you can easily firewall your admin actions in the security settings of your application. By keeping everything blog related to one bundle, you maintain good code organization.

The same goes for a UserBundle. It's helpful to remind yourself that a bundle should represent a set of like functionality for an application. So if you have code that fetches blog posts, and allows you to create and manage them, they naturally group together in a single bundle.

2
votes

I asked a similar question here: How to share a Symfony2 model with several projects

I went with the 'ModelBundle' approach that contains all the entities, forms, repositories, etc. These are all shared with the FrontendBundle and BackendBundle. So far I'm very happy with this solution.