User Tools

Site Tools


symfony:symfony_tutorial_notes:the_bundle_system

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
symfony:symfony_tutorial_notes:the_bundle_system [2015/09/17 00:54] – created mithatsymfony:symfony_tutorial_notes:the_bundle_system [2015/09/18 04:04] (current) – [Bundle Directory Structure] mithat
Line 1: Line 1:
-The Bundle System  +====== The Bundle System ====== 
- +  
-Everything in Symfomy is a bundle. +**Everything** is a bundle. 
-  * ''src/AppBundle'' is your app. +  * ''src/AppBundle/'' is your app. 
-  * ''vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle'' is the framework itself. +  * ''vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/'' is the framework itself. 
-  * [[http://symfony.com/doc/current/book/bundles.html#third-party-bundles|Third party bundles]]+  * [[http://knpbundles.com/|Third party bundles]]
   * In reality, a bundle can live anywhere as long as it can be autoloaded (via ''app/autoload.php'').   * In reality, a bundle can live anywhere as long as it can be autoloaded (via ''app/autoload.php'').
  
-====== Enabling bundles ======+===== Enabling bundles =====
  
 Enabling bundles is done by hacking ''AppKernel.registerBundles()'': Enabling bundles is done by hacking ''AppKernel.registerBundles()'':
Line 36: Line 36:
 </file> </file>
  
 +===== Creating a Bundle =====
 +To create ''AcmeTestBundle'' manually:
 +  - create a ''src/Acme/TestBundle/'' directory and add ''AcmeTestBundle.php'':<file php src/Acme/TestBundle/AcmeTestBundle.php>
 +namespace Acme\TestBundle;
 +
 +use Symfony\Component\HttpKernel\Bundle\Bundle;
 +
 +class AcmeTestBundle extends Bundle
 +{
 +}
 +</file>
 +  - enable it via the AppKernel class:<file php app/AppKernel.php>
 +public function registerBundles()
 +{
 +    $bundles = array(
 +        // ...
 +        // register your bundle
 +        new Acme\TestBundle\AcmeTestBundle(),
 +    );
 +    // ...
 +
 +    return $bundles;
 +}
 +</file>
 +  - Hack on controllers, etc.
 +
 +To create ''AcmeTestBundle'' via the command line:
 +  * <code bash>$ php app/console generate:bundle --namespace=Acme/TestBundle</code>
 +
 +The bundle skeleton generates a basic controller, template, and routing resource.
 +
 +The ''generate:bundle'' command adds the new bundle to ''AppKernel.registerBundles()''.
 +
 +See [[http://symfony.com/doc/current/cookbook/bundles/best_practices.html#bundles-naming-conventions|Bundle Naming Conventions]].
 +
 +===== Bundle Directory Structure =====
 +
 +By default, the bundle system follows a set of conventions that help to keep code consistent:
 +
 +  * ''Controller/'': Contains the controllers of the bundle (e.g. RandomController.php).
 +  * ''DependencyInjection/'': Holds certain Dependency Injection Extension classes, which may import service configuration, register compiler passes or more (this directory is not necessary).
 +  * ''Resources/config/'': Houses configuration, including routing configuration (e.g. routing.yml).
 +  * ''Resources/views/'': Holds templates organized by controller name (e.g. Hello/index.html.twig).
 +  * ''Resources/public/'': Contains web assets (images, stylesheets, etc) and is copied or symbolically linked into the project web/ directory via the assets:install console command.
 +  * ''Tests/'': Holds all tests for the bundle. 
 +    
 +<WRAP center round tip 100%>
 +Note that the current [[http://symfony.com/doc/current/best_practices/index.html|best practices]] for the ''AppBundle'' are:
 +  * **config** goes in ''app/config/'' (rather than ''src/AppBundle/Resources/config/'')
 +  * **controllers** go in ''src/AppBundle/Controller/'' (as expected).
 +  * **views** go in ''app/Resources/views/'' (rather than ''src/AppBundle/Resources/views/'')
 +  * **assets** go in ''web/''
 +  * **tests** go in TBD
 +</WRAP>
  
symfony/symfony_tutorial_notes/the_bundle_system.1442451291.txt.gz · Last modified: 2015/09/17 00:54 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki