User Tools

Site Tools


symfony:symfony_tutorial_notes:configuring_symfony

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:configuring_symfony [2015/09/16 22:00] – created mithatsymfony:symfony_tutorial_notes:configuring_symfony [2015/09/16 23:35] (current) mithat
Line 1: Line 1:
-====== Configuring Symfony ======+====== Configuring Symfony (and Environments) ====== 
 +The main configuration file lives in the app/config/ as a YAML, XML, (and/?) or PHP file. Only YAML is considered here. 
 + 
 +<file yaml app/config/config.yml> 
 +imports: 
 +    - { resource: parameters.yml } 
 +    - { resource: security.yml } 
 + 
 +framework: 
 +    secret:          "%secret%" 
 +    router:          { resource: "%kernel.root_dir%/config/routing.yml"
 +    # ... 
 + 
 +# Twig Configuration 
 +twig: 
 +    debug:            "%kernel.debug%" 
 +    strict_variables: "%kernel.debug%" 
 + 
 +# ... 
 +</file>
  
 ===== Default Configuration Dump ===== ===== Default Configuration Dump =====
 +Dump the default configuration for a bundle in YAML to the console:
 +<code bash>
 +$ app/console config:dump-reference FrameworkBundle  # using Bundle name
 +$ app/console config:dump-reference framework        # using configuration key
 +</code>
 +
 +===== Environments =====
 +
 +Different environments share the same PHP code (apart from the front controller), but use different configuration. A Symfony project generally begins with three environments: ''dev'', ''test'', and ''prod''.
 +
 +  * Access ''dev'': http://localhost/app_dev.php/random/10
 +  * Access ''prod'': http://localhost/app.php/random/10
 +  * The ''test'' environment is used when running automated tests and cannot be accessed directly through the browser. See the [[http://symfony.com/doc/current/book/testing.html|testing chapter]].
 +
 +To clear ''prod'' cache, rebuid stuff, etc.:
 +<code bash>
 +$ php app/console cache:clear --env=prod --no-debug
 +</code>
 +
 +==== Additional Environments ====
 +
 +To create a new environment, copy ''web/app.php'' (or ''web/app_dev.php''?) to a new file and in that file associate the AppKernel with a new environment name in the ''AppKernel'' ctor;
 +<code php>
 +$kernel = new AppKernel('newname', false);
 +</code>
  
-==== Environments ====+Then create a config file that matches the environment name but prefixed with ''config_'':
  
-===== Environment Configuration =====+<file yaml app/config/config_newname.yml> 
 +imports: 
 +    - { resource: config.yml }
  
 +framework:
 +    router:   { resource: "%kernel.root_dir%/config/routing_dev.yml" }
 +    profiler: { only_exceptions: false }
  
 +# ...
 +</file>
symfony/symfony_tutorial_notes/configuring_symfony.1442440832.txt.gz · Last modified: 2015/09/16 22:00 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki