Symfony bundle scaffolding with subfolders - symfony

According to this well-known article:
https://blog.liip.ch/archive/2011/05/19/symfony2-bundle-structure-a-use-case.html
Is there a fast way to scaffold a bundle with Frontend and Backend subfolders?

I haven't heard of something like that. And I don't see any advantage of it.
This also means I don't think you should have both backend and frontend in the same bundle. Id avise you to make two seperate bundles.
Project\Something\BackendBundle
Project\Something\FrontendBundle
You can do that using app/console generate:bundle
This will result in a Project/Something folder structure with both bundles in the same Something folder.

Related

Where to save your TWIG templates in Symfony framework

What is the best place to keep your TWIG template and why?
app/Resources/views folder
or
YourBundle/Resources/views
Traditionally, Symfony developers stored the application templates in
the Resources/views/ directory of each bundle. Then they used the
logical name to refer to them (e.g.
AcmeDemoBundle:Default:index.html.twig).
But for the templates used in your application, it's much more
convenient to store them in the app/Resources/views/ directory.
Syfmony Documentation
In Symfony 2, auto generated twig files were located in YourBundle/Resources/views
In Symfony 3, auto generated twig files are located in app/Resources/views
When developing your application, best place is YourBundle/Resources/views. It will be more consistent and probably it will be easier to maintain and eventually, decouple your bundle for installation in other projects.
I find app/Resources/views useful to override other bundle's templates, for example when creating Error pages http://symfony.com/doc/current/cookbook/controller/error_pages.html
It depends of your bundles architecture. The point is to be consistent with your current architecture.
From the official doc:
For most projects, you should store everything inside the AppBundle
If you use a main bundle structure (like a big AppBundle with many small domain bundles) then you probably want to centralize your templates in App or the ressources of your main Bundle.
But if you use a functionnal bundles (like EmailBundle, UserBundle, Invoice Bundle) then you probably want to ignore the symfony best practice and put the concerned twig in these bundles.

About the default AppBundle in Symfony2

When creating a new SF2 project, the project contains an AppBundle by default. Should this be removed like the AcmeDemoBundle?
Symfony best practice
For most projects, you should store everything inside the AppBundle.
http://symfony.com/doc/current/best_practices/business-logic.html
Multiple bundles
I tend to create multiple bundles, e.g. I have these bundles in src/:
MyProjectEntityBundle
MyProjectBackendBundle
MyProjectHomePageBundle
And for reusable components I create a symfony bundle that I put into a git repository and load it via composer using satis. So for example I have some bundles in vendor/:
VendorCmsUtilBundle
VendorImageThumbnailBundle
"Domain Driven Design (DDD)"
I have yet to try this approach (I will soon):
http://williamdurand.fr/2013/08/07/ddd-with-symfony2-folder-structure-and-code-first/
As #Marcel Burkhard pointed out, the AppBundle is where you should put all your application logic according to Symfony best practices. Of course you can throw it away and build your own, but it's definitely not like the Acme Demo bundle.
I disagree with the strategy of splitting Entities and Frontend / Backend in different bundles.
I agree with the strategy of creating your own "utility" bundle(s) so that you can reuse your code in different projects via composer.

Where to place Application bundles?

I have an application written with Symfony and want to merge some small bundles as part of that app.
Regarding the quick Symfony2 bundle tour from Sonata, I need an ApplicationBundle.
quick Symfony2 bundle tour:
There are two types of bundles:
Application Bundle (AB),
Vendor Bundle (VB), that should not be modified inside a project.
The AB directory is where developers implement the project requirements,
An AB can overwrite almost everything from a VB, example: you can redefine a VB template at the AB level.
(Source)
Symfony documentation says about architecture:
The directory structure of a Symfony application is rather flexible,
but the recommended structure is as follows:
app/: the application configuration;
src/: the project's PHP code;
vendor/: the third-party dependencies;
web/: the web root directory
(Source)
But where shall I place it?
There are two possibilities:
app/Application (Sonata EasyExtends places ApplicationBundles here)
src
But what is the right one?
And why are there two possibilities?
The Symfony documentation doesn't cover ApplicationBundle.
Thanks for any hints.
The documentation say that :
Application Bundles (in 2 words, this is important) are stored in src/ directory.
Vendor Bundles are stored in vendor/directory (and came from your composer.json dependencies).
You can (and should) create many bundles for you application.

Create a bundle in vendors in Symfony2

I am trying to create a bundle in vendors in Symfony2.
MyBundle(MineUserBundle) needs to inherit other two bundle in vendors FOSUserBundle and HWIOAuthBundle.
How to get inherit both bundles properties, templates etc in Mybundle?
vendors
FOSUserBundle
HWIOAuthBundle
MineUserBundle
Here MineUserBundle needs to have all features of other two bundle.
How to get the process work?
Since you are using namespaces it does not mater into which folder you are going to deploy your Bundle. Just include use statements in your bundle with ones you need:
use Path\To\FOS\UserBundle;
use Path\ToHWIO\AuthBundle;
And you can extend whatever you need.
But if you really want to install your bundle to vendor directory, then you have to configure define it in your deps file.
[YourVendorYouBundle]
git=git#github.com:yourRepository/YourVendorYouBundle.git
target=/bundles/YourVendor/YouBundle

Deleting not needed bundles from Symfony 2?

Is possible to delete bundles not needed in order to keep the project clean? I'm using Symfony2 with propel to build a RESTful interface. Don't need:
Twig
Doctrine2 (i prefer Propel instead)
Assetic (without Twig assetic does not make sense, correct me if i'm wrong)
Security (no need to model roles)
I can't find any how-to in order to remove uneeded bundles. Any help is much appreciated.
EDIT: monlog is the logger, not mongodb. Need it!
About deps.lock file: it can be removed after removing bundles, than issue:
php bin/vendors update
and i should be recreated. It maintains the git version id checked out, for each bundle.
Sure. Remove them from AppKernel then delete from the file system if you want. You could even edit the deps file to keep them from coming back. Twig and Assetic are independent. You could use the Assetic bundle with straight PHP.
In case anyone else runs into this issue, you can follow the instructions in the Symfony2 docs to remove the Acme Bundle: http://symfony.com/doc/2.0/cookbook/bundles/remove.html
The proccess is like this:
delete /src/Test/BlogBundle directory
change /app/config/routing.yml file to remove the bundle routes
Unregister your bundle from /app/AppKernel.php
clear cache (either by deleting cache/{$env} or console cache:clear)

Resources