diff --git a/book/doctrine.rst b/book/doctrine.rst
index 534baad9282..6b03e686698 100644
--- a/book/doctrine.rst
+++ b/book/doctrine.rst
@@ -62,16 +62,44 @@ information. By convention, this information is usually configured in an
The parameters defined in that file are referenced by the main configuration
file when setting up Doctrine:
- .. code-block:: yaml
-
- # app/config/config.yml
- doctrine:
- dbal:
- driver: "%database_driver%"
- host: "%database_host%"
- dbname: "%database_name%"
- user: "%database_user%"
- password: "%database_password%"
+ .. configuration-block::
+
+ .. code-block:: yaml
+
+ # app/config/config.yml
+ doctrine:
+ dbal:
+ driver: "%database_driver%"
+ host: "%database_host%"
+ dbname: "%database_name%"
+ user: "%database_user%"
+ password: "%database_password%"
+
+ .. code-block:: xml
+
+
+
+
+
+
+ .. code-block:: php
+
+ // app/config/config.php
+ $configuration->loadFromExtension('doctrine', array(
+ 'dbal' => array(
+ 'driver' => '%database_driver%',
+ 'host' => '%database_host%',
+ 'dbname' => '%database_name%',
+ 'user' => '%database_user%',
+ 'password' => '%database_password%',
+ ),
+ ));
By separating the database information into a separate file, you can
easily keep different versions of the file on each server. You can also
@@ -909,6 +937,24 @@ To relate the ``Category`` and ``Product`` entities, start by creating a
mappedBy: category
# don't forget to init the collection in entity __construct() method
+ .. code-block:: xml
+
+
+
+
+
+
+
+
+
+
+
First, since a ``Category`` object will relate to many ``Product`` objects,
a ``products`` array property is added to hold those ``Product`` objects.
@@ -966,6 +1012,28 @@ object, you'll want to add a ``$category`` property to the ``Product`` class:
name: category_id
referencedColumnName: id
+ .. code-block:: xml
+
+
+
+
+
+
+
+
+
+
+
+
Finally, now that you've added a new property to both the ``Category`` and
``Product`` classes, tell Doctrine to generate the missing getter and setter
methods for you:
@@ -1387,6 +1455,21 @@ and ``nullable``. Take a few examples:
length: 150
unique: true
+ .. code-block:: xml
+
+
+
+
+
.. note::
There are a few more options not listed here. For more details, see
diff --git a/cookbook/doctrine/dbal.rst b/cookbook/doctrine/dbal.rst
index 78f1f6c1e98..2dbcb9d3823 100644
--- a/cookbook/doctrine/dbal.rst
+++ b/cookbook/doctrine/dbal.rst
@@ -38,7 +38,7 @@ To get started, configure the database connection parameters:
.. code-block:: xml
- // app/config/config.xml
+
+ .. code-block:: php
+
+ use Symfony\Component\DependencyInjection\Definition;
+
+ $container->loadFromExtension('doctrine', array(
+ 'dbal' => array(
+ 'default_connection' => 'default',
+ 'connections' => array(
+ 'default' => array(
+ 'driver' => 'pdo_sqlite',
+ 'memory' => true,
+ ),
+ ),
+ ),
+ ));
+
+ $container
+ ->setDefinition(
+ 'my.listener',
+ new Definition('Acme\SearchBundle\EventListener\SearchIndexer')
+ )
+ ->addTag('doctrine.event_listener', array('event' => 'postPersist'))
+ ;
+ $container
+ ->setDefinition(
+ 'my.listener2',
+ new Definition('Acme\SearchBundle\EventListener\SearchIndexer2')
+ )
+ ->addTag('doctrine.event_listener', array('event' => 'postPersist', 'connection' => 'default'))
+ ;
+ $container
+ ->setDefinition(
+ 'my.subscriber',
+ new Definition('Acme\SearchBundle\EventListener\SearchIndexerSubscriber')
+ )
+ ->addTag('doctrine.event_subscriber', array('connection' => 'default'))
+ ;
+
Creating the Listener Class
---------------------------
@@ -99,7 +137,7 @@ a ``postPersist`` method, which will be called when the event is thrown::
// perhaps you only want to act on some "Product" entity
if ($entity instanceof Product) {
- // do something with the Product
+ // ... do something with the Product
}
}
}
diff --git a/cookbook/doctrine/file_uploads.rst b/cookbook/doctrine/file_uploads.rst
index 9da44db2cd8..6fc7e0b9e14 100644
--- a/cookbook/doctrine/file_uploads.rst
+++ b/cookbook/doctrine/file_uploads.rst
@@ -22,7 +22,7 @@ will be covered in this cookbook entry.
Basic Setup
-----------
-First, create a simple Doctrine Entity class to work with::
+First, create a simple ``Doctrine`` Entity class to work with::
// src/Acme/DemoBundle/Entity/Document.php
namespace Acme\DemoBundle\Entity;
@@ -118,20 +118,68 @@ look like this::
}
Next, create this property on your ``Document`` class and add some validation
-rules::
+rules:
- // src/Acme/DemoBundle/Entity/Document.php
+.. configuration-block::
- // ...
- class Document
- {
- /**
- * @Assert\File(maxSize="6000000")
- */
- public $file;
+ .. code-block:: yaml
+
+ # src/Acme/DemoBundle/Resources/config/validation.yml
+ Acme\DemoBundle\Entity\Document:
+ properties:
+ file:
+ - File:
+ maxSize: 6000000
+
+ .. code-block:: php-annotations
+
+ // src/Acme/DemoBundle/Entity/Document.php
+ namespace Acme\DemoBundle\Entity;
// ...
- }
+ use Symfony\Component\Validator\Constraints as Assert;
+
+ class Document
+ {
+ /**
+ * @Assert\File(maxSize="6000000")
+ */
+ public $file;
+
+ // ...
+ }
+
+ .. code-block:: xml
+
+
+
+
+
+
+
+
+
+
+ .. code-block:: php
+
+ // src/Acme/DemoBundle/Entity/Document.php
+ namespace Acme\DemoBundle\Entity;
+
+ // ...
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
+ use Symfony\Component\Validator\Constraints as Assert;
+
+ class Document
+ {
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata)
+ {
+ $metadata->addPropertyConstraint('file', new Assert\File(array(
+ 'maxSize' => 6000000,
+ )));
+ }
+ }
.. note::
@@ -141,6 +189,7 @@ rules::
The following controller shows you how to handle the entire process::
+ // ...
use Acme\DemoBundle\Entity\Document;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
// ...
@@ -176,15 +225,27 @@ The following controller shows you how to handle the entire process::
When writing the template, don't forget to set the ``enctype`` attribute:
- .. code-block:: html+jinja
+ .. configuration-block::
+
+ .. code-block:: html+jinja
+
+
Upload File
+
+
+
+ .. code-block:: html+php
-
Upload File
+
Upload File
-
+
+
The previous controller will automatically persist the ``Document`` entity
with the submitted name, but it will do nothing about the file and the ``path``
diff --git a/cookbook/doctrine/multiple_entity_managers.rst b/cookbook/doctrine/multiple_entity_managers.rst
index 89c09465a32..73707e4fc97 100644
--- a/cookbook/doctrine/multiple_entity_managers.rst
+++ b/cookbook/doctrine/multiple_entity_managers.rst
@@ -56,6 +56,99 @@ The following configuration code shows how you can configure two entity managers
mappings:
AcmeCustomerBundle: ~
+ .. code-block:: xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ .. code-block:: php
+
+ $container->loadFromExtension('doctrine', array(
+ 'dbal' => array(
+ 'default_connection' => 'default',
+ 'connections' => array(
+ 'default' => array(
+ 'driver' => '%database_driver%',
+ 'host' => '%database_host%',
+ 'port' => '%database_port%',
+ 'dbname' => '%database_name%',
+ 'user' => '%database_user%',
+ 'password' => '%database_password%',
+ 'charset' => 'UTF8',
+ ),
+ 'customer' => array(
+ 'driver' => '%database_driver2%',
+ 'host' => '%database_host2%',
+ 'port' => '%database_port2%',
+ 'dbname' => '%database_name2%',
+ 'user' => '%database_user2%',
+ 'password' => '%database_password2%',
+ 'charset' => 'UTF8',
+ ),
+ ),
+ ),
+
+ 'orm' => array(
+ 'default_entity_manager' => 'default',
+ 'entity_managers' => array(
+ 'default' => array(
+ 'connection' => 'default',
+ 'mappings' => array(
+ 'AcmeDemoBundle' => null,
+ 'AcmeStoreBundle' => null,
+ ),
+ ),
+ 'customer' => array(
+ 'connection' => 'customer',
+ 'mappings' => array(
+ 'AcmeCustomerBundle' => null,
+ ),
+ ),
+ ),
+ ),
+ ));
+
In this case, you've defined two entity managers and called them ``default``
and ``customer``. The ``default`` entity manager manages entities in the
``AcmeDemoBundle`` and ``AcmeStoreBundle``, while the ``customer`` entity