myapp/config/settings.yml file contains the main symfony configuration for the
myapp application. You have already seen the function of many settings from this file in the previous chapters, but let's revisit them.
As explained in Chapter 5, this file is environment-dependent, which means that each setting can take a different value for each environment. Remember that each parameter defined in this file is accessible from inside the PHP code via the
sfConfig class. The parameter name is the setting name prefixed with
sf_. For instance, if you want to get the value of the
cache parameter, you just need to call
19.1.1. Default Modules and Actions
When a routing rule doesn't define the
module or the
action parameter, values from the
settings.yml file are used instead:
modulerequest parameter. Defaults to the
actionrequest parameter. Defaults to the
Symfony provides default pages for special situations. In the case of a routing error, symfony executes an action of the
default module, which is stored in the
$sf_symfony_data_dir/modules/default/ directory. The
settings.yml file defines which action is executed depending on the error:
error_404_action: Action called when the URL entered by the user doesn't match any route or when an
sfError404Exceptionoccurs. The default value is
login_action: Action called when a nonauthenticated user tries to access a page defined as
security.yml(see Chapter 6 for details). The default value is
secure_action: Action called when a user doesn't have the credentials required for an action. The default value is
module_disabled_action: Action called when a user requests a module declared as disabled in
module.yml. The default value is
unavailable_action: Action called when a user requests a page from a disabled application. The default value is
default/unavailable. To disable an application, set the
Before deploying an application to production, you should customize these actions, because the
default module templates include the symfony logo on the page. See Figure 19-1 for a screenshot of one of these pages, the error 404 page.
You can override the default pages in two ways:
- You can create your own default module in the application's
modules/directory, override all the actions defined in the
unavailable) and all the related templates (
- You can change the default module and action settings of the
settings.ymlfile to use pages of your application.
Two other pages bear a symfony look and feel, and they also need to be customized before deployment to production. These pages are not in the
default module, because they are called when symfony cannot run properly. Instead, you will find these default pages in the
error500.php: Page called when an internal server error occurs in the production environment. In other environments (where
SF_DEBUGis set to
true), when an error occurs, symfony displays the full execution stack and an explicit error message (see Chapter 16 for details).
unavailable.php: Page called when a user requests a page while the cache is being cleared (that is, between a call to the
symfony clear-cachetask and the end of this task execution). On systems with a very large cache, the cache-clearing process can take several seconds. Symfony cannot execute a request with a partially cleared cache, so requests received before the end of the process are redirected to this page.
To customize these pages, simply create
unavailable.php pages in your application's
web/errors/ directory. Symfony will use these instead of its own.
Note To have requests redirected to the
unavailable.php page when needed, you need to set the
check_lock setting to
on in the application
settings.yml. The check is deactivated by default, because it adds a very slight overhead for every request.
19.1.2. Optional Feature Activation
Some parameters of the
settings.yml file control optional framework features that can be enabled or disabled. Deactivating unused features boosts performances a bit, so make sure to review the settings listed in Table 19-1 before deploying your application.
Table 19-1 - Optional Features Set Through
||Enables the database manager. Set it to
||Enables security features (secure actions and credentials; see Chapter 6). The default security filter (
||Enables the flash parameter feature (see Chapter 6). Set it to
||Enables interface translation (see Chapter 13). Set it to
||Enables logging of symfony events. Set it to off when you want to ignore the logging.yml settings and turn symfony logging off completely.||
||Enables and defines the policy of the output escaping feature (see Chapter 7). Set it to
||Enables template caching (see Chapter 12). Set it to
||Enables the web debug toolbar for easy debugging (see Chapter 16). Set it to
||Enables the check of the symfony version for every request. Set it to on for automatic cache clearing after a framework upgrade. Leave it set to off if you always clear the cache after an upgrade.||
||Enables the application lock system, triggered by the
||Enables PHP response compression. Set it to
||Enables symfony optimizations based on PHP accelerators. When such an accelerator (for instance, APC, XCache, or eAccelerator) is installed, symfony takes advantage of its features to keep objects and configuration in memory between requests. Set the parameter to
19.1.3. Feature Configuration
Symfony uses some parameters of
settings.yml to alter the behavior of built-in features such as form validation, cache, and third-party modules.
126.96.36.199. Output Escaping Settings
Output escaping settings control the way the variables are accessible in the template (see Chapter 7). The
settings.yml file includes two settings for this feature:
escaping_strategysetting can take the value
- The escaping_method setting can be set to
188.8.131.52. Routing Settings
Two routing settings (see Chapter 9) are stored in
suffixparameter sets the default suffix for generated URLs. The default value is a period (
.), and it corresponds to no suffix. Set it to
.html, for instance, to have all generated URLs look like static pages.
no_script_nameparameter enables the front controller name in generated URLs. The
no_script_namesetting can be on only for a single application in a project, unless you store the front controllers in various directories and alter the default URL rewriting rules. It is usually on for the production environment of your main application and off for the others.
184.108.40.206. Form Validation Settings
Form validation settings control the way error messages output by the
Validation helpers look (see Chapter 10). These errors are included in
<div> tags, and they use the
validation_error_ class setting as a
class attribute and the
validation_error_id_prefix setting to build up the
id attribute. The default values are
error_for_, so the attributes output by a call to the
form_error() helper for an input named
foobar will be
Two settings determine which characters precede and follow each error message:
validation_error_suffix. You can change them to customize all error messages at once.
220.127.116.11. Cache Settings
Cache settings are defined in
cache.yml for the most part, except for two in
cache enables the template cache mechanism, and
etag enables ETag handling on the server side (see Chapter 15).
18.104.22.168. Logging Settings
Two logging settings (see Chapter 16) are stored in
error_reportingspecifies which events are logged in the PHP logs. By default, it is set to 341 for the production environment (so the logged events are
E_USER_ERROR) and to 4095 for the development environment (
web_debugsetting activates the web debug toolbar. Set it to
ononly in the development and test environments.
22.214.171.124. Paths to Assets
settings.yml file also stores paths to assets. If you want to use another version of the asset than the one bundled with symfony, you can change these path settings:
- Prototype libraries stored in
- Files needed by the administration generator stored in
- Files needed by the web debug toolbar stored in
126.96.36.199. Default Helpers
Default helpers, loaded for every template, are declared in the
standard_helpers setting (see Chapter 7). By default, these are the
Form helper groups. If you use a helper group in all templates of an application, adding its name to the
standard_helpers setting saves you the hassle of declaring it with
use_helper() on each template.
188.8.131.52. Activated Modules
Activated modules from plug-ins or from the symfony core are declared in the
enabled_modules parameter. Even if a plug-in bundles a module, users can't request this module unless it is declared in
default module, which provides the default symfony pages (congratulations, page not found, and so on), is the only enabled module by default.
184.108.40.206. Character Set
The character set of the responses is a general setting of the application, because it is used by many components of the framework (templates, output escaper, helpers, and so on). Defined in the
charset setting, its default (and advised) value is
220.127.116.11. Miscellaneous Configuration
settings.yml file contains a few more parameters, used internally by symfony for core behaviors. Listing 19-1 lists them as they appear in the configuration file.
Listing 19-1 - Miscellaneous Configuration Settings, in
# Remove comments in core framework classes as defined in the core_compile.yml strip_comments: on # Functions called when a class is requested and not already loaded # Expects an array of callables. Used by the framework bridges. autoloading_functions: ~ # Session timeout, in seconds timeout: 1800 # Maximum number of forwards followed by the action before raising an exception max_forwards: 5 # Global constants path_info_array: SERVER path_info_key: PATH_INFO url_format: PATH