Skip to content

[WIP] Add missing formats #2248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 93 additions & 10 deletions book/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!-- app/config/config.xml -->
<doctrine:config>
<doctrine:dbal
driver="%database_driver%"
host="%database_host%"
dbname="%database_name%"
user="%database_user%"
password="%database_password%"
>
</doctrine:config>

.. 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
Expand Down Expand Up @@ -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

<!-- src/Acme/StoreBundle/Resources/config/doctrine/Category.orm.xml -->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Acme\StoreBundle\Entity\Category">
<!-- ... -->
<one-to-many field="products"
target-entity="product"
mapped-by="category"
/>

<!-- don't forget to init the collection in entity __construct() method -->
</entity>
</doctrine-mapping>

First, since a ``Category`` object will relate to many ``Product`` objects,
a ``products`` array property is added to hold those ``Product`` objects.
Expand Down Expand Up @@ -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

<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Acme\StoreBundle\Entity\Product">
<!-- ... -->
<many-to-one field="category"
target-entity="products"
join-column="category"
>
<join-column
name="category_id"
referenced-column-name="id"
/>
</many-to-one>
</entity>
</doctrine-mapping>

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:
Expand Down Expand Up @@ -1387,6 +1455,21 @@ and ``nullable``. Take a few examples:
length: 150
unique: true

.. code-block:: xml

<!--
A string field length 255 that cannot be null
(reflecting the default values for the "length" and *nullable* options)
type attribute is necessary in yaml definitions
-->
<field name="name" type="string" />
<field name="email"
type="string"
column="email_address"
length="150"
unique="true"
/>

.. note::

There are a few more options not listed here. For more details, see
Expand Down
56 changes: 46 additions & 10 deletions cookbook/configuration/apache_router.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,33 @@ Change Router Configuration Parameters
To dump Apache routes you must first tweak some configuration parameters to tell
Symfony2 to use the ``ApacheUrlMatcher`` instead of the default one:

.. code-block:: yaml
.. configuration-block::

# app/config/config_prod.yml
parameters:
router.options.matcher.cache_class: ~ # disable router cache
router.options.matcher_class: Symfony\Component\Routing\Matcher\ApacheUrlMatcher
.. code-block:: yaml

# app/config/config_prod.yml
parameters:
router.options.matcher.cache_class: ~ # disable router cache
router.options.matcher_class: Symfony\Component\Routing\Matcher\ApacheUrlMatcher

.. code-block:: xml

<!-- app/config/config_prod.xml -->
<parameters>
<parameter key="router.options.matcher.cache_class">null</parameter> <!-- disable router cache -->
<parameter key="router.options.matcher_class">
Symfony\Component\Routing\Matcher\ApacheUrlMatcher
</parameter>
</parameters>

.. code-block:: php

// app/config/config_prod.php
$container->setParameter('router.options.matcher.cache_class', null); // disable router cache
$container->setParameter(
'router.options.matcher_class',
'Symfony\Component\Routing\Matcher\ApacheUrlMatcher'
);

.. tip::

Expand All @@ -33,13 +54,28 @@ Generating mod_rewrite rules

To test that it's working, let's create a very basic route for demo bundle:

.. code-block:: yaml
.. configuration-block::

.. code-block:: yaml

# app/config/routing.yml
hello:
pattern: /hello/{name}
defaults: { _controller: AcmeDemoBundle:Demo:hello }

.. code-block:: xml

<!-- app/config/routing.xml -->
<route id="hello" pattern="/hello/{name}">
<default key="_controller">AcmeDemoBundle:Demo:hello</default>
</route>

# app/config/routing.yml
hello:
pattern: /hello/{name}
defaults: { _controller: AcmeDemoBundle:Demo:hello }
.. code-block:: php

// app/config/routing.php
$collection->add('hello', new Route('/hello/{name}', array(
'_controller' => 'AcmeDemoBundle:Demo:hello',
)));

Now generate **url_rewrite** rules:

Expand Down
16 changes: 12 additions & 4 deletions cookbook/configuration/external_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,19 @@ key, and define the type as ``constant``.
This only works for XML configuration. If you're *not* using XML, simply
import an XML file to take advantage of this functionality:

.. code-block:: yaml
.. configuration-block::

.. code-block:: yaml

# app/config/config.yml
imports:
- { resource: parameters.xml }

.. code-block:: php

// app/config/config.php
$loader->import('parameters.xml');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did not add XML version because previous paragraph states: "If you're not using XML".


# app/config/config.yml
imports:
- { resource: parameters.xml }

Miscellaneous Configuration
---------------------------
Expand Down
29 changes: 24 additions & 5 deletions cookbook/configuration/override_dir_structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,33 @@ may need to modify the paths inside these files::
If you use the AsseticBundle you need to configure this, so it can use
the correct ``web`` directory:

.. code-block:: yaml
.. configuration-block::

# app/config/config.yml
.. code-block:: yaml

# app/config/config.yml

# ...
assetic:
# ...
read_from: "%kernel.root_dir%/../../public_html"
assetic:
# ...
read_from: "%kernel.root_dir%/../../public_html"

.. code-block:: xml

<!-- app/config/config.xml -->

<!-- ... -->
<assetic:config read-from="%kernel.root_dir%/../../public_html" />

.. code-block:: php

// app/config/config.php

// ...
$container->loadFromExtension('assetic', array(
// ...
'read_from' => '%kernel.root_dir%/../../public_html',
));

Now you just need to dump the assets again and your application should
work:
Expand Down
8 changes: 3 additions & 5 deletions cookbook/doctrine/dbal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To get started, configure the database connection parameters:

.. code-block:: xml

// app/config/config.xml
<!-- app/config/config.xml -->
<doctrine:config>
<doctrine:dbal
name="default"
Expand All @@ -64,9 +64,7 @@ To get started, configure the database connection parameters:
For full DBAL configuration options, see :ref:`reference-dbal-configuration`.

You can then access the Doctrine DBAL connection by accessing the
``database_connection`` service:

.. code-block:: php
``database_connection`` service::

class UserController extends Controller
{
Expand Down Expand Up @@ -186,4 +184,4 @@ mapping type:
.. _`PDO`: http://www.php.net/pdo
.. _`Doctrine`: http://www.doctrine-project.org
.. _`DBAL Documentation`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/index.html
.. _`Custom Mapping Types`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types
.. _`Custom Mapping Types`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types
40 changes: 39 additions & 1 deletion cookbook/doctrine/event_listeners_subscribers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,44 @@ managers that use this connection.
</services>
</container>

.. 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
---------------------------

Expand All @@ -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
}
}
}
Expand Down
Loading