Symfony Bundles Cookbook: Difference between revisions
(Created page with "== Overview == Topics related to working with bundles in Symfony. == Generating a new bundle skeleton == === Basic syntax === <syntaxhighlight lang="powershell"> d:\path\t...") |
m (→Basic syntax) |
||
| (10 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Symfony]] [[Category:PHP]] [[Category:CMS]] [[Category:Web Development]] | |||
== Overview == | == Overview == | ||
Topics related to working with bundles in Symfony. | Topics related to working with bundles in Symfony.<ref>[http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html Generating a New Bundle Skeleton] (Symfony documentation)</ref> | ||
== Generating a new bundle skeleton == | == Generating a new bundle skeleton == | ||
=== Basic syntax === | === Basic syntax === | ||
<p class="alert 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.</p> | |||
<syntaxhighlight lang="powershell"> | <syntaxhighlight lang="powershell"> | ||
| Line 15: | Line 18: | ||
=== Bundle properties === | === 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. | The `generate:bundle` command without any arguments will enter into interactive mode and respond with a series of prompts for the bundle properties. Each of the prompts has a corresponding argument for the command line. | ||
* ''' | * '''Namespace''' (`--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 | ** ''Vendor'' is a company name, project name, client name, etc. specific to the website and/or project | ||
** ''Sub-namespaces'' organize related bundles | ** ''Sub-namespaces'' organize related bundles | ||
** The ''bundle'' name must end in "Bundle". | ** The ''bundle'' name must end in "Bundle". | ||
** E.g. `NorthRose/Billing/InvoiceBundle` | ** 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`. | * '''Bundle name''' (`--bundle-name`) name used to reference the bundle. Should be unique. Convention is to concatenate all of the namespace parts, e.g. `NorthRoseInvoiceBundle`. | ||
* ''' | * '''Directory''' (`--dir`) Default convention is in `/src/`. | ||
* '''Configuration format''' yml, xml, php, etc. Convention is to use yml. | * '''Configuration format''' (`--format`) e.g. `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. | * '''Do you want to generate the whole directory structure?''' (`--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 === | === Permissions === | ||
| Line 37: | Line 42: | ||
* Explorer > navigate to the `app` directory. | * Explorer > navigate to the `app` directory. | ||
* Right click on the subdirectory > Properties > Security tab > Edit > Users > add "Modify" permissions | * 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. | |||
'''Clear the cache directly 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, | |||
<syntaxhighlight lang="powershell"> | |||
d:\path\to\webroot\> php app/console cache:clear | |||
</syntaxhighlight> | |||
Specific environments can be targeted with the `--env` parameter: | |||
<syntaxhighlight lang="powershell"> | |||
d:\path\to\webroot\> php app/console cache:clear --env=prod | |||
</syntaxhighlight> | |||
== Reference == | |||
=== See also === | === See also === | ||
* [http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html Generating a New Bundle Skeleton] ( | * [http://symfony.com/doc/current/cookbook/bundles/best_practices.html Best Practices for Reusable Bundles] (Symfony Cookbook) | ||
* [http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html Generating a New Bundle Skeleton] (Symfony documentation) | |||
=== Notes === | |||
<references /> | |||
Latest revision as of 16:54, 26 September 2018
Overview[edit]
Topics related to working with bundles in Symfony.[1]
Generating a new bundle skeleton[edit]
Basic syntax[edit]
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.
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[edit]
The generate:bundle command without any arguments will enter into interactive mode and respond with a series of prompts for the bundle properties. Each of the prompts has a corresponding argument for the command line.
- Namespace (
--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 (
--bundle-name) name used to reference the bundle. Should be unique. Convention is to concatenate all of the namespace parts, e.g.NorthRoseInvoiceBundle. - Directory (
--dir) Default convention is in/src/. - Configuration format (
--format) e.g.yml,xml,php, etc. Convention is to use yml. - Do you want to generate the whole directory structure? (
--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[edit]
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[edit]
The observations about clearing the cache are not confirmed as of yet. These are working observations.
Clear the cache directly 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[edit]
See also[edit]
- Best Practices for Reusable Bundles (Symfony Cookbook)
- Generating a New Bundle Skeleton (Symfony documentation)
Notes[edit]
- ↑ Generating a New Bundle Skeleton (Symfony documentation)