1
votes

I have been using Symfony1.4 for over 2.5 years. Now there is a new project and the client wants to use Symfony2 for this project.

After studying Symfony2 for few weeks now I have few things to decide for my structure which ideally would organize properly in Symfony1.4 but I cannot find perfect ways to do in Symfony2 (may be because of my not much experience with Symfony2 yet)

  1. I have 3 applications in the project. Do i create bundles for these 3 applications? Or do I create 3 apps folder in the src/ directory and create bundles for individual modules of the respective applications?

  2. If we create bundle for each application for Q1 above, I am not able to find a way to organize the modules wise entities within the same bundle. For eg. I have modules like Users, Events, Calendar etc for the module frontend, how can i organize the modules within the frontendBundle?

  3. Common code for all apps was stored in the root lib/ folder in Symfony1.4 and it used to become accessible across all apps. I am not able to understand where to have this common code? Do I have that inside vendors folder? Or vendors folder is just meant for purpose of third part plugged extensions like Doctrine?

Please can some Symfony2 experts clarify these doubts?

1

1 Answers

1
votes
  1. You create 3 different bundles

  2. There are two approaches.

    a) You create everything in flat structure for entities, repositories etc (business logic generally). And for views, config, translates etc. you create separate namespaces (and therefore directories) base on controllers structure. Eg.

    src/
        COMPANY/
            App1Bundle/
                Controller/
                    UsersController.php
                    EventsController.php
                    ...
                Entity/
                    User.php
                    Even.php
                    ...
                Repository/
                    UserRepository.php
                    ...
                Model/
                    SomeServiceRelatedToUsers.php
                    SomeServiceRelatedToEvents.php
                    ...
                Resources/
                    views/
                        Users/
                            someUserView.twig.html
                        Events/
                            someEventsView.twig.html
    

    b) and second approach - you create separate namespaces for different logic parts. Eg.

    src/
        COMPANY/
            App1Bundle/
                Controller/
                    Users/
                        UserSpecificController1.php
                        UserSpecificController2.php 
                    Events/
                        EventsSpecificController1.php
                        EventsSpecificController1.php
                     ...
                Entity/
                    Users/
                        User.php
                    Events/
                        Even.php
                    ...
                Repository/
                    Users/
                        UserRepository.php
                    ...
                Model/
                    Users/
                        SomeServiceRelatedToUsers.php
                    Events/
                        SomeServiceRelatedToEvents.php
                    ...
                Resources/
                    views/
                        Users/
                            someUserView.twig.html
                        Events/
                            someEventsView.twig.html
    

    I prefer first one.

  3. You create separate bundle for this, like CommonBundle or sth. Some people prefer way where you create such common code as a vendor library and then create bundle which is some bridge between your library and symfony app.

Here are links which might be useful for you: