Symfony Bundles Cookbook

From Littledamien Wiki
Jump to navigation Jump to search

Overview

Topics related to working with bundles in Symfony.

Generating a new bundle skeleton

Basic syntax

d:\path\to\webroot\> php app/console generate:bundle

N.B. The generate:bundle command takes a long time to execute and send a response.

Bundle properties

The generate:bundle command without any arguments will enter into interactive mode and respond with a series of prompts for the bundle properties.

  • namespace "vendor" followed by one or more optional category sub-namespaces followed by the bundle name.
    • Vendor is a company name, project name, client name, etc. specific to the website and/or project
    • Sub-namespaces organize related bundles
    • The bundle name must end in "Bundle".
    • E.g. NorthRose/Billing/InvoiceBundle
  • Bundle name name used to reference the bundle. Should be unique. Convention is to concatenate all of the namespace parts, e.g. NorthRoseInvoiceBundle.
  • Target directory Default convention is in /src/.
  • Configuration format yml, xml, php, etc. Convention is to use yml.
  • Do you want to generate the whole directory structure? This will create a complete directory structure including empty public folders for documentation, web assets, etc. Shortcut to create skeleton structure.
  • There is a prompt to update the app kernel to include the new bundle. Yes. This basically registers the bundle with the app by updating /app/AppKernel.php
  • There is a prompt to update the routing to include the new bundle. This updates the default routing configuration to register the new bundle by udpating /app/config/routing.yml

Permissions

Working remotely on Windows, it's necessary to make sure that some of the directories under /app/ have write permissions:

  • /app/cache/
  • /app/logs/
  • Remote desktop to the server.
  • Explorer > navigate to the app directory.
  • Right click on the subdirectory > Properties > Security tab > Edit > Users > add "Modify" permissions

See also