Skip to content

Commit b8512f7

Browse files
committed
Merge branch '2.1'
2 parents bd9ea95 + 5333cb3 commit b8512f7

File tree

6 files changed

+129
-15
lines changed

6 files changed

+129
-15
lines changed

book/forms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ You can also define whole logic inline by using a Closure::
439439
'validation_groups' => function(FormInterface $form) {
440440
$data = $form->getData();
441441
if (Entity\Client::TYPE_PERSON == $data->getType()) {
442-
return array('person')
442+
return array('person');
443443
} else {
444444
return array('company');
445445
}

cookbook/console/console_command.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ How to create a Console Command
55
===============================
66

77
The Console page of the Components section (:doc:`/components/console/introduction`) covers
8-
how to create a Console command. This cookbook articles covers the differences
8+
how to create a Console command. This cookbook article covers the differences
99
when creating Console commands within the Symfony2 framework.
1010

1111
Automatically Registering Commands

cookbook/console/generating_urls.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.. index::
2+
single: Console; Generating URLs
3+
4+
How to generate URLs with a custom Host in Console Commands
5+
===========================================================
6+
7+
Unfortunately, the command line context does not know about your VirtualHost
8+
or domain name. This means that if if you generate absolute URLs within a
9+
Console Command you'll probably end up with something like ``http://localhost/foo/bar``
10+
which is not very useful.
11+
12+
To fix this, you need to configure the "request context", which is a fancy
13+
way of saying that you need to configure your environment so that it knows
14+
what URL it should use when generating URLs.
15+
16+
There are two ways of configuring the request context: at the application level
17+
and per Command.
18+
19+
Configuring the Request Context globally
20+
----------------------------------------
21+
22+
To configure the Request Context - which is used by the URL Generator - you can
23+
redefine the parameters it uses as default values to change the default host
24+
(localhost) and scheme (http). Note that this does not impact URLs generated
25+
via normal web requests, since those will override the defaults.
26+
27+
.. configuration-block::
28+
29+
.. code-block:: yaml
30+
31+
# app/config/parameters.yml
32+
parameters:
33+
router.request_context.host: example.org
34+
router.request_context.scheme: https
35+
36+
.. code-block:: xml
37+
38+
<?xml version="1.0" encoding="UTF-8"?>
39+
40+
<container xmlns="http://symfony.com/schema/dic/services"
41+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
42+
43+
<parameters>
44+
<parameter key="router.request_context.host">example.org</parameter>
45+
<parameter key="router.request_context.scheme">https</parameter>
46+
</parameters>
47+
</container>
48+
49+
.. code-block:: php
50+
51+
// app/config/config_test.php
52+
$container->setParameter('router.request_context.host', 'example.org');
53+
$container->setParameter('router.request_context.scheme', 'https');
54+
55+
Configuring the Request Context per Command
56+
-------------------------------------------
57+
58+
To change it only in one command you can simply fetch the Request Context
59+
service and override its settings::
60+
61+
// src/Acme/DemoBundle/Command/DemoCommand.php
62+
// ...
63+
64+
class DemoCommand extends ContainerAwareCommand
65+
{
66+
protected function execute(InputInterface $input, OutputInterface $output)
67+
{
68+
$context = $this->getContainer()->get('router')->getContext();
69+
$context->setHost('example.com');
70+
$context->setScheme('https');
71+
72+
// ... your code here
73+
}
74+
}
75+

cookbook/console/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Console
66

77
console_command
88
usage
9+
generating_urls

cookbook/doctrine/multiple_entity_managers.rst

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
.. index::
22
single: Doctrine; Multiple entity managers
33

4-
How to work with Multiple Entity Managers
5-
=========================================
4+
How to work with Multiple Entity Managers and Connections
5+
=========================================================
66

7-
You can use multiple entity managers in a Symfony2 application. This is
8-
necessary if you are using different databases or even vendors with entirely
9-
different sets of entities. In other words, one entity manager that connects
10-
to one database will handle some entities while another entity manager that
11-
connects to another database might handle the rest.
7+
You can use multiple Doctrine entity managers or connections in a Symfony2
8+
application. This is necessary if you are using different databases or even
9+
vendors with entirely different sets of entities. In other words, one entity
10+
manager that connects to one database will handle some entities while another
11+
entity manager that connects to another database might handle the rest.
1212

1313
.. note::
1414

@@ -23,6 +23,26 @@ The following configuration code shows how you can configure two entity managers
2323
.. code-block:: yaml
2424
2525
doctrine:
26+
dbal:
27+
default_connection: default
28+
connections:
29+
default:
30+
driver: %database_driver%
31+
host: %database_host%
32+
port: %database_port%
33+
dbname: %database_name%
34+
user: %database_user%
35+
password: %database_password%
36+
charset: UTF8
37+
customer:
38+
driver: %database_driver2%
39+
host: %database_host2%
40+
port: %database_port2%
41+
dbname: %database_name2%
42+
user: %database_user2%
43+
password: %database_password2%
44+
charset: UTF8
45+
2646
orm:
2747
default_entity_manager: default
2848
entity_managers:
@@ -39,17 +59,34 @@ The following configuration code shows how you can configure two entity managers
3959
In this case, you've defined two entity managers and called them ``default``
4060
and ``customer``. The ``default`` entity manager manages entities in the
4161
``AcmeDemoBundle`` and ``AcmeStoreBundle``, while the ``customer`` entity
42-
manager manages entities in the ``AcmeCustomerBundle``.
62+
manager manages entities in the ``AcmeCustomerBundle``. You've also defined
63+
two connections, one for each entity manager.
64+
65+
.. note::
66+
67+
When working with multiple connections and entity managers, you should be
68+
explicit about which configuration you want. If you *do* omit the name of
69+
the connection or entity manager, the default (i.e. ``default``) is used.
70+
71+
When working with multiple connections to create your databases:
72+
73+
.. code-block:: bash
74+
75+
# Play only with "default" connection
76+
$ php app/console doctrine:database:create
77+
78+
# Play only with "customer" connection
79+
$ php app/console doctrine:database:create --connection=customer
80+
81+
When working with multiple entity managers to update your schema:
4382

44-
When working with multiple entity managers, you should be explicit about which
45-
entity manager you want. If you *do* omit the entity manager's name when you
46-
update your schema, the default (i.e. ``default``) is used::
83+
.. code-block:: bash
4784
4885
# Play only with "default" mappings
49-
php app/console doctrine:schema:update --force
86+
$ php app/console doctrine:schema:update --force
5087
5188
# Play only with "customer" mappings
52-
php app/console doctrine:schema:update --force --em=customer
89+
$ php app/console doctrine:schema:update --force --em=customer
5390
5491
If you *do* omit the entity manager's name when asking for it,
5592
the default entity manager (i.e. ``default``) is returned::

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
* :doc:`/cookbook/console/console_command`
3030
* :doc:`/cookbook/console/usage`
31+
* :doc:`/cookbook/console/generating_urls`
3132

3233
* :doc:`/cookbook/controller/index`
3334

0 commit comments

Comments
 (0)