1

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 Answers1

1
  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:

Community
  • 1
  • 1
Cyprian
  • 11,174
  • 1
  • 48
  • 45
  • For the first 2 questions I asked, what if we create 2 folders backend, frontend. Then using the create bundle command create User bundle under frontend folder? Also instead of app folder create apps folder and have 2 folder frontend, backend for individual apps? Will this not separate the application wise bundles for me? – thebestcoders Aug 30 '12 at 07:49
  • I'm not sure if I understood correctly what you mean. You want to create two application (in s 1.4 meaning). "frontend" and "backend". So you create sth like this: in src/ dir create dir with your company name (it's just convention), and there you create two bundles: AdminBundle and AppBundle (instead of backend/frontend - in correctly meaning frontend is your user interfaces/views and backend is business logic and controllers). Then you create let's say UserController (or Event or wht you want) inside AppBundle. – Cyprian Aug 30 '12 at 08:15
  • you need to change your approach. In Symfony2 there is no such thing like module or/and app. Logically independent things create separate bundles. And inside particularly bundles you can create separate namespaces to extract some "modules". If you have more questions or more clarify just ask. Best regards! – Cyprian Aug 30 '12 at 08:19