Symfony Bundles Cookbook: Difference between revisions
| Line 8: | Line 8: | ||
=== Basic syntax === | === Basic syntax === | ||
< | <div class="alert-warning">Install bundles only from the server itself. Installing them from a prompt on a remote machine can inject the local path into the application path causing errors to the effect that resources are outside the paths that are accessible to PHP.</div> | ||
<syntaxhighlight lang="powershell"> | <syntaxhighlight lang="powershell"> | ||
Revision as of 18:39, 2 March 2015
Overview
Topics related to working with bundles in Symfony.[1]
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
appdirectory. - Right click on the subdirectory > Properties > Security tab > Edit > Users > add "Modify" permissions
Clearing the cache
The observations about clearing the cache are not confirmed as of yet. These are working observations.
Only clear the cache on the server. Clearing it remotely can inject the local path into the cache, causing errors to the effect that the resource is outside the directories that PHP has access to.
The application cache can interfere with routing. If a routing change doesn't seem to have any effect,
d:\path\to\webroot\> php app/console cache:clear
Specific environments can be targeted with the --env parameter:
d:\path\to\webroot\> php app/console cache:clear --env=prod
Reference
See also
- Best Practices for Reusable Bundles (Symfony Cookbook)
- Generating a New Bundle Skeleton (Symfony documentation)
Notes
- ↑ Generating a New Bundle Skeleton (Symfony documentation)