0
votes

Using Symfony2 for one of my structure. I wanted to keep modules and the various files related to modules abstract from other module files.

So for eg. I have frontend application. Under frontend application I have users, gallery modules. I want to keep all the files related to users in one place and all the files related to gallery in one place. This way I achieve the abstraction at module level the way it is provided in Symfony1.4.

Following is the folder structure I achieved till here.

    web/
       admin.php
       frontend.php

    apps/
        autoload.php # this autloads the common libaries/vendors for all application eg. CommonBundle
        admin/
               AppKernel.php
               AppAutoload.php # load application specific libraries
               bootstrap.php.cache
               config/
               cache/
               .
               .
               .
            frontend/
               AppKernel.php
                AppAutoload.php
               bootstrap.php.cache
               config/
               cache/
               .
               .
               .

    src/
        Admin/
            UserBundle/
                Controller/
                    UsersController.php
                Entity/
                    User.php
                Repository/
                    UserRepository.php
                Resources/
                    views/
                     indexUserView.twig.html
            DiaryBundle/
                Controller/
                    DiaryController.php
                Entity/
                    Diary.php
                Repository/
                    DiaryRepository.php
                Resources/
                    views/
                     indexDiaryView.twig.html
        Frontend/
            UserBundle/
                Controller/
                    UsersController.php
                Entity/
                    User.php
                Repository/
                    UserRepository.php
                Resources/
                    views/
                     indexUserView.twig.html
            DiaryBundle/
                Controller/
                    DiaryController.php
                Entity/
                    Diary.php
                Repository/
                    DiaryRepository.php
                Resources/
                    views/
                     indexDiaryView.twig.html

I am confident about my above folder structure. But as I found Symfony2 community supporting creation of Bundle's at Application level and not at module level, I wanted to know the pros and cons of creating Bundles at module level. What can be the possible pit falls of creation at module level?

I can see many advantages of having Bundles for modules

  1. All the Controller, Views, Models of a module are at same place and abstract from Controller, Models, Views of other modules. This way person working on one module has to work inside one folder only and not bother about person's work going on in module2 i.e Bundle2

  2. Clear cache can happen at the application level using below command clear cache for just frontend application

    shell> php apps/frontend/console cache:clear

  3. If you need to create a bundle in frontend application, command is below. It creates UserBundle under src/frontend application. It also register the bundle name inside apps/frontend/AppKernel.php.

    shell> php apps/frontend/console generate:bundle --namespace=frontend/userBundle --format=yml

so everything seems fine. But it seems Symfony2 community does not think this approach to be correct?

Please suggest loop holes in my approach?

2

2 Answers

1
votes

I think you should not do that...

There is no such thing module in Symfony2. There is a cookbook article which explaining the difference between Symfony2 and symfony1. I think you are talking about different applications. You can have different applications, but it is not recommended, you should create an another project and share bundles.

I think this project you would like to achieve will break a lot of things and you will not be able to use third-party bundles anymore.

There is/was an initiative called KnpRad to make Symfony2's project structure more RAD friendly, but they had a lot of issues and this project seems dead for now.

Quote from their blog:

In the current implementation, Symfony2 has hardcoded paths to bundle resources almost everywhere. It means, that in order to change the folders structure, we would need to override all those Symfony2 commands, extensions and compiler passes. It created a divide in our codebases and introduced BC breaks with some bundles.

0
votes

Neetu.. Symfony1.4 and symfony2 has big difference. As per symfony2 you need to generate your application under src folder here application name would be namespace and under namespace you can create bundle that is called module in symfony1.4. commands are :

php app/console generate:bundle --namespace=Yournamespace/yourBundle --format=yml php app/console cache:clear --env=prod --no-debug you can create apps as per your need.