.. index::
single: Doctrine; ORM configuration reference
single: Configuration reference; Doctrine ORM
Doctrine Configuration Reference
================================
.. configuration-block::
.. code-block:: yaml
doctrine:
dbal:
default_connection: default
types:
# A collection of custom types
# Example
some_custom_type:
class: Acme\HelloBundle\MyCustomType
commented: true
connections:
default:
dbname: database
# A collection of different named connections (e.g. default, conn2, etc)
default:
dbname: ~
host: localhost
port: ~
user: root
password: ~
charset: ~
path: ~
memory: ~
# The unix socket to use for MySQL
unix_socket: ~
# True to use as persistent connection for the ibm_db2 driver
persistent: ~
# The protocol to use for the ibm_db2 driver (default to TCPIP if omitted)
protocol: ~
# True to use dbname as service name instead of SID for Oracle
service: ~
# The session mode to use for the oci8 driver
sessionMode: ~
# True to use a pooled server with the oci8 driver
pooled: ~
# Configuring MultipleActiveResultSets for the pdo_sqlsrv driver
MultipleActiveResultSets: ~
driver: pdo_mysql
platform_service: ~
logging: %kernel.debug%
profiling: %kernel.debug%
driver_class: ~
wrapper_class: ~
options:
# an array of options
key: []
mapping_types:
# an array of mapping types
name: []
slaves:
# a collection of named slave connections (e.g. slave1, slave2)
slave1:
dbname: ~
host: localhost
port: ~
user: root
password: ~
charset: ~
path: ~
memory: ~
# The unix socket to use for MySQL
unix_socket: ~
# True to use as persistent connection for the ibm_db2 driver
persistent: ~
# The protocol to use for the ibm_db2 driver (default to TCPIP if omitted)
protocol: ~
# True to use dbname as service name instead of SID for Oracle
service: ~
# The session mode to use for the oci8 driver
sessionMode: ~
# True to use a pooled server with the oci8 driver
pooled: ~
# Configuring MultipleActiveResultSets for the pdo_sqlsrv driver
MultipleActiveResultSets: ~
orm:
default_entity_manager: ~
auto_generate_proxy_classes: false
proxy_dir: %kernel.cache_dir%/doctrine/orm/Proxies
proxy_namespace: Proxies
# search for the "ResolveTargetEntityListener" class for a cookbook about this
resolve_target_entities: []
entity_managers:
# A collection of different named entity managers (e.g. some_em, another_em)
some_em:
query_cache_driver:
type: array # Required
host: ~
port: ~
instance_class: ~
class: ~
metadata_cache_driver:
type: array # Required
host: ~
port: ~
instance_class: ~
class: ~
result_cache_driver:
type: array # Required
host: ~
port: ~
instance_class: ~
class: ~
connection: ~
class_metadata_factory_name: Doctrine\ORM\Mapping\ClassMetadataFactory
default_repository_class: Doctrine\ORM\EntityRepository
auto_mapping: false
hydrators:
# An array of hydrator names
hydrator_name: []
mappings:
# An array of mappings, which may be a bundle name or something else
mapping_name:
mapping: true
type: ~
dir: ~
alias: ~
prefix: ~
is_bundle: ~
dql:
# a collection of string functions
string_functions:
# example
# test_string: Acme\HelloBundle\DQL\StringFunction
# a collection of numeric functions
numeric_functions:
# example
# test_numeric: Acme\HelloBundle\DQL\NumericFunction
# a collection of datetime functions
datetime_functions:
# example
# test_datetime: Acme\HelloBundle\DQL\DatetimeFunction
# Register SQL Filters in the entity manager
filters:
# An array of filters
some_filter:
class: ~ # Required
enabled: false
.. code-block:: xml
bar
string
Acme\HelloBundle\MyCustomType
Acme\HelloBundle\DQL\StringFunction
Acme\HelloBundle\DQL\NumericFunction
Acme\HelloBundle\DQL\DatetimeFunction
Configuration Overview
----------------------
This following configuration example shows all the configuration defaults that
the ORM resolves to:
.. code-block:: yaml
doctrine:
orm:
auto_mapping: true
# the standard distribution overrides this to be true in debug, false otherwise
auto_generate_proxy_classes: false
proxy_namespace: Proxies
proxy_dir: "%kernel.cache_dir%/doctrine/orm/Proxies"
default_entity_manager: default
metadata_cache_driver: array
query_cache_driver: array
result_cache_driver: array
There are lots of other configuration options that you can use to overwrite
certain classes, but those are for very advanced use-cases only.
Caching Drivers
~~~~~~~~~~~~~~~
For the caching drivers you can specify the values "array", "apc", "memcache", "memcached",
"xcache" or "service".
The following example shows an overview of the caching configurations:
.. code-block:: yaml
doctrine:
orm:
auto_mapping: true
metadata_cache_driver: apc
query_cache_driver:
type: service
id: my_doctrine_common_cache_service
result_cache_driver:
type: memcache
host: localhost
port: 11211
instance_class: Memcache
Mapping Configuration
~~~~~~~~~~~~~~~~~~~~~
Explicit definition of all the mapped entities is the only necessary
configuration for the ORM and there are several configuration options that you
can control. The following configuration options exist for a mapping:
* ``type`` One of ``annotation``, ``xml``, ``yml``, ``php`` or ``staticphp``.
This specifies which type of metadata type your mapping uses.
* ``dir`` Path to the mapping or entity files (depending on the driver). If
this path is relative it is assumed to be relative to the bundle root. This
only works if the name of your mapping is a bundle name. If you want to use
this option to specify absolute paths you should prefix the path with the
kernel parameters that exist in the DIC (for example %kernel.root_dir%).
* ``prefix`` A common namespace prefix that all entities of this mapping
share. This prefix should never conflict with prefixes of other defined
mappings otherwise some of your entities cannot be found by Doctrine. This
option defaults to the bundle namespace + ``Entity``, for example for an
application bundle called ``AcmeHelloBundle`` prefix would be
``Acme\HelloBundle\Entity``.
* ``alias`` Doctrine offers a way to alias entity namespaces to simpler,
shorter names to be used in DQL queries or for Repository access. When using
a bundle the alias defaults to the bundle name.
* ``is_bundle`` This option is a derived value from ``dir`` and by default is
set to true if dir is relative proved by a ``file_exists()`` check that
returns false. It is false if the existence check returns true. In this case
an absolute path was specified and the metadata files are most likely in a
directory outside of a bundle.
.. index::
single: Configuration; Doctrine DBAL
single: Doctrine; DBAL configuration
.. _`reference-dbal-configuration`:
Doctrine DBAL Configuration
---------------------------
DoctrineBundle supports all parameters that default Doctrine drivers
accept, converted to the XML or YAML naming standards that Symfony
enforces. See the Doctrine `DBAL documentation`_ for more information.
The following block shows all possible configuration keys:
.. configuration-block::
.. code-block:: yaml
doctrine:
dbal:
dbname: database
host: localhost
port: 1234
user: user
password: secret
driver: pdo_mysql
# the DBAL driverClass option
driver_class: MyNamespace\MyDriverImpl
# the DBAL driverOptions option
options:
foo: bar
path: "%kernel.data_dir%/data.sqlite"
memory: true
unix_socket: /tmp/mysql.sock
# the DBAL wrapperClass option
wrapper_class: MyDoctrineDbalConnectionWrapper
charset: UTF8
logging: "%kernel.debug%"
platform_service: MyOwnDatabasePlatformService
mapping_types:
enum: string
types:
custom: Acme\HelloBundle\MyCustomType
# the DBAL keepSlave option
keep_slave: false
.. code-block:: xml
bar
string
Acme\HelloBundle\MyCustomType
If you want to configure multiple connections in YAML, put them under the
``connections`` key and give them a unique name:
.. code-block:: yaml
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: Symfony2
user: root
password: null
host: localhost
customer:
dbname: customer
user: root
password: null
host: localhost
The ``database_connection`` service always refers to the *default* connection,
which is the first one defined or the one configured via the
``default_connection`` parameter.
Each connection is also accessible via the ``doctrine.dbal.[name]_connection``
service where ``[name]`` if the name of the connection.
.. _DBAL documentation: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html