Skip to content

Commit 91b440c

Browse files
committed
[Cookbook/doctrine] Added missing formats
1 parent b303f9d commit 91b440c

File tree

4 files changed

+213
-23
lines changed

4 files changed

+213
-23
lines changed

cookbook/doctrine/dbal.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ To get started, configure the database connection parameters:
3838
3939
.. code-block:: xml
4040
41-
// app/config/config.xml
41+
<!-- app/config/config.xml -->
4242
<doctrine:config>
4343
<doctrine:dbal
4444
name="default"
@@ -64,9 +64,7 @@ To get started, configure the database connection parameters:
6464
For full DBAL configuration options, see :ref:`reference-dbal-configuration`.
6565

6666
You can then access the Doctrine DBAL connection by accessing the
67-
``database_connection`` service:
68-
69-
.. code-block:: php
67+
``database_connection`` service::
7068

7169
class UserController extends Controller
7270
{
@@ -186,4 +184,4 @@ mapping type:
186184
.. _`PDO`: http://www.php.net/pdo
187185
.. _`Doctrine`: http://www.doctrine-project.org
188186
.. _`DBAL Documentation`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/index.html
189-
.. _`Custom Mapping Types`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types
187+
.. _`Custom Mapping Types`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types

cookbook/doctrine/event_listeners_subscribers.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,44 @@ managers that use this connection.
7777
</services>
7878
</container>
7979
80+
.. code-block:: php
81+
82+
use Symfony\Component\DependencyInjection\Definition;
83+
84+
$container->loadFromExtension('doctrine', array(
85+
'dbal' => array(
86+
'default_connection' => 'default',
87+
'connections' => array(
88+
'default' => array(
89+
'driver' => 'pdo_sqlite',
90+
'memory' => true,
91+
),
92+
),
93+
),
94+
));
95+
96+
$container
97+
->setDefinition(
98+
'my.listener',
99+
new Definition('Acme\SearchBundle\EventListener\SearchIndexer')
100+
)
101+
->addTag('doctrine.event_listener', array('event' => 'postPersist'))
102+
;
103+
$container
104+
->setDefinition(
105+
'my.listener2',
106+
new Definition('Acme\SearchBundle\EventListener\SearchIndexer2')
107+
)
108+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'connection' => 'default'))
109+
;
110+
$container
111+
->setDefinition(
112+
'my.subscriber',
113+
new Definition('Acme\SearchBundle\EventListener\SearchIndexerSubscriber')
114+
)
115+
->addTag('doctrine.event_subscriber', array('connection' => 'default'))
116+
;
117+
80118
Creating the Listener Class
81119
---------------------------
82120

@@ -99,7 +137,7 @@ a ``postPersist`` method, which will be called when the event is thrown::
99137

100138
// perhaps you only want to act on some "Product" entity
101139
if ($entity instanceof Product) {
102-
// do something with the Product
140+
// ... do something with the Product
103141
}
104142
}
105143
}

cookbook/doctrine/file_uploads.rst

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ will be covered in this cookbook entry.
2222
Basic Setup
2323
-----------
2424

25-
First, create a simple Doctrine Entity class to work with::
25+
First, create a simple ``Doctrine`` Entity class to work with::
2626

2727
// src/Acme/DemoBundle/Entity/Document.php
2828
namespace Acme\DemoBundle\Entity;
@@ -118,20 +118,68 @@ look like this::
118118
}
119119

120120
Next, create this property on your ``Document`` class and add some validation
121-
rules::
121+
rules:
122122

123-
// src/Acme/DemoBundle/Entity/Document.php
123+
.. configuration-block::
124124

125-
// ...
126-
class Document
127-
{
128-
/**
129-
* @Assert\File(maxSize="6000000")
130-
*/
131-
public $file;
125+
.. code-block:: yaml
126+
127+
# src/Acme/DemoBundle/Resources/config/validation.yml
128+
Acme\DemoBundle\Entity\Document:
129+
properties:
130+
file:
131+
- File:
132+
maxSize: 6000000
133+
134+
.. code-block:: php-annotations
135+
136+
// src/Acme/DemoBundle/Entity/Document.php
137+
namespace Acme\DemoBundle\Entity;
132138
133139
// ...
134-
}
140+
use Symfony\Component\Validator\Constraints as Assert;
141+
142+
class Document
143+
{
144+
/**
145+
* @Assert\File(maxSize="6000000")
146+
*/
147+
public $file;
148+
149+
// ...
150+
}
151+
152+
.. code-block:: xml
153+
154+
<!-- src/Acme/DemoBundle/Resources/config/validation.yml -->
155+
<class name="Acme\DemoBundle\Entity\Document">
156+
<property name="file">
157+
<constraint name="File">
158+
<option name="maxSize">6000000</option>
159+
</constraint>
160+
</property>
161+
</class>
162+
163+
.. code-block:: php
164+
165+
// src/Acme/DemoBundle/Entity/Document.php
166+
namespace Acme\DemoBundle\Entity;
167+
168+
// ...
169+
use Symfony\Component\Validator\Mapping\ClassMetadata;
170+
use Symfony\Component\Validator\Constraints as Assert;
171+
172+
class Document
173+
{
174+
// ...
175+
176+
public static function loadValidatorMetadata(ClassMetadata $metadata)
177+
{
178+
$metadata->addPropertyConstraint('file', new Assert\File(array(
179+
'maxSize' => 6000000,
180+
)));
181+
}
182+
}
135183
136184
.. note::
137185

@@ -141,6 +189,7 @@ rules::
141189

142190
The following controller shows you how to handle the entire process::
143191

192+
// ...
144193
use Acme\DemoBundle\Entity\Document;
145194
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
146195
// ...
@@ -176,15 +225,27 @@ The following controller shows you how to handle the entire process::
176225

177226
When writing the template, don't forget to set the ``enctype`` attribute:
178227

179-
.. code-block:: html+jinja
228+
.. configuration-block::
229+
230+
.. code-block:: html+jinja
231+
232+
<h1>Upload File</h1>
233+
234+
<form action="#" method="post" {{ form_enctype(form) }}>
235+
{{ form_widget(form) }}
236+
237+
<input type="submit" value="Upload Document" />
238+
</form>
239+
240+
.. code-block:: html+php
180241

181-
<h1>Upload File</h1>
242+
<h1>Upload File</h1>
182243

183-
<form action="#" method="post" {{ form_enctype(form) }}>
184-
{{ form_widget(form) }}
244+
<form action="#" method="post" <?php echo $view['form']->enctype($form) ?>>
245+
<?php echo $view['form']->widget($form) ?>
185246

186-
<input type="submit" value="Upload Document" />
187-
</form>
247+
<input type="submit" value="Upload Document" />
248+
</form>
188249

189250
The previous controller will automatically persist the ``Document`` entity
190251
with the submitted name, but it will do nothing about the file and the ``path``

cookbook/doctrine/multiple_entity_managers.rst

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,99 @@ The following configuration code shows how you can configure two entity managers
5656
mappings:
5757
AcmeCustomerBundle: ~
5858
59+
.. code-block:: xml
60+
61+
<?xml version="1.0" encoding="UTF-8"?>
62+
63+
<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
64+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
65+
xmlns:srv="http://symfony.com/schema/dic/services"
66+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
67+
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
68+
69+
<config>
70+
<dbal default-connection="default">
71+
<connection name="default"
72+
driver="%database_driver%"
73+
host="%database_host%"
74+
port="%database_port%"
75+
dbname="%database_name%"
76+
user="%database_user%"
77+
password="%database_password%"
78+
charset="UTF8"
79+
/>
80+
81+
<connection name="customer"
82+
driver="%database_driver2%"
83+
host="%database_host2%"
84+
port="%database_port2%"
85+
dbname="%database_name2%"
86+
user="%database_user2%"
87+
password="%database_password2%"
88+
charset="UTF8"
89+
/>
90+
</dbal>
91+
92+
<orm default-entity-manager="default">
93+
<entity-manager name="default" connection="default">
94+
<mapping name="AcmeDemoBundle" />
95+
<mapping name="AcmeStoreBundle" />
96+
</entity-manager>
97+
98+
<entity-manager name="customer" connection="customer">
99+
<mapping name="AcmeCustomerBundle" />
100+
</entity-manager>
101+
</orm>
102+
</config>
103+
</srv:container>
104+
105+
.. code-block:: php
106+
107+
$container->loadFromExtension('doctrine', array(
108+
'dbal' => array(
109+
'default_connection' => 'default',
110+
'connections' => array(
111+
'default' => array(
112+
'driver' => '%database_driver%',
113+
'host' => '%database_host%',
114+
'port' => '%database_port%',
115+
'dbname' => '%database_name%',
116+
'user' => '%database_user%',
117+
'password' => '%database_password%',
118+
'charset' => 'UTF8',
119+
),
120+
'customer' => array(
121+
'driver' => '%database_driver2%',
122+
'host' => '%database_host2%',
123+
'port' => '%database_port2%',
124+
'dbname' => '%database_name2%',
125+
'user' => '%database_user2%',
126+
'password' => '%database_password2%',
127+
'charset' => 'UTF8',
128+
),
129+
),
130+
),
131+
132+
'orm' => array(
133+
'default_entity_manager' => 'default',
134+
'entity_managers' => array(
135+
'default' => array(
136+
'connection' => 'default',
137+
'mappings' => array(
138+
'AcmeDemoBundle' => null,
139+
'AcmeStoreBundle' => null,
140+
),
141+
),
142+
'customer' => array(
143+
'connection' => 'customer',
144+
'mappings' => array(
145+
'AcmeCustomerBundle' => null,
146+
),
147+
),
148+
),
149+
),
150+
));
151+
59152
In this case, you've defined two entity managers and called them ``default``
60153
and ``customer``. The ``default`` entity manager manages entities in the
61154
``AcmeDemoBundle`` and ``AcmeStoreBundle``, while the ``customer`` entity

0 commit comments

Comments
 (0)