Skip to content

Commit 1629d49

Browse files
committed
Merge branch '2.0' into 2.1
Conflicts: cookbook/security/entity_provider.rst reference/forms/twig_reference.rst
2 parents f64157e + a0483b4 commit 1629d49

File tree

8 files changed

+220
-3
lines changed

8 files changed

+220
-3
lines changed

book/security.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,8 @@ is defined by the ``target`` parameter above (e.g. the ``homepage``). For
15961596
more information on configuring the logout, see the
15971597
:doc:`Security Configuration Reference</reference/configuration/security>`.
15981598

1599+
.. _book-security-template:
1600+
15991601
Access Control in Templates
16001602
---------------------------
16011603

book/templating.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,8 @@ in your application configuration:
701701
.. index::
702702
single: Templating; Linking to pages
703703

704+
.. _book-templating-pages:
705+
704706
Linking to Pages
705707
~~~~~~~~~~~~~~~~
706708

@@ -818,6 +820,8 @@ correctly:
818820
.. index::
819821
single: Templating; Linking to assets
820822

823+
.. _book-templating-assets:
824+
821825
Linking to Assets
822826
~~~~~~~~~~~~~~~~~
823827

book/translation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ Translations in Templates
720720
Most of the time, translation occurs in templates. Symfony2 provides native
721721
support for both Twig and PHP templates.
722722

723+
.. _book-translation-twig:
724+
723725
Twig Templates
724726
~~~~~~~~~~~~~~
725727

cookbook/security/entity_provider.rst

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ focus on the most important methods that come from the
5454
* @ORM\Table(name="acme_users")
5555
* @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
5656
*/
57-
class User implements UserInterface
57+
class User implements UserInterface, \Serializable
5858
{
5959
/**
6060
* @ORM\Column(type="integer")
@@ -132,6 +132,26 @@ focus on the most important methods that come from the
132132
public function eraseCredentials()
133133
{
134134
}
135+
136+
/**
137+
* @see \Serializable::serialize()
138+
*/
139+
public function serialize()
140+
{
141+
return serialize(array(
142+
$this->id,
143+
));
144+
}
145+
146+
/**
147+
* @see \Serializable::unserialize()
148+
*/
149+
public function unserialize($serialized)
150+
{
151+
list (
152+
$this->id,
153+
) = unserialize($serialized);
154+
}
135155
}
136156
137157
In order to use an instance of the ``AcmeUserBundle:User`` class in the Symfony
@@ -168,6 +188,15 @@ For more details on each of these, see :class:`Symfony\\Component\\Security\\Cor
168188
return $this->username === $user->getUsername();
169189
}
170190
191+
.. note::
192+
193+
The :phpclass:`Serializable` interface and its ``serialize`` and ``unserialize``
194+
methods have been added to allow the ``User`` class to be serialized
195+
to the session. This may or may not be needed depending on your setup,
196+
but it's probably a good idea. Only the ``id`` needs to be serialized,
197+
because the :method:`Symfony\\Bridge\\Doctrine\\Security\\User\\EntityUserProvider::refreshUser`
198+
method reloads the user on each request by using the ``id``.
199+
171200
Below is an export of my ``User`` table from MySQL. For details on how to
172201
create user records and encode their password, see :ref:`book-security-encoding-user-password`.
173202

@@ -368,7 +397,7 @@ The code below shows the implementation of the
368397
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class));
369398
}
370399

371-
return $this->loadUserByUsername($user->getUsername());
400+
return $this->find($user->getId());
372401
}
373402

374403
public function supportsClass($class)
@@ -429,7 +458,7 @@ returns the list of related groups::
429458
use Doctrine\Common\Collections\ArrayCollection;
430459
// ...
431460

432-
class User implements AdvancedUserInterface
461+
class User implements AdvancedUserInterface, \Serializable
433462
{
434463
/**
435464
* @ORM\ManyToMany(targetEntity="Group", inversedBy="users")
@@ -448,6 +477,26 @@ returns the list of related groups::
448477
{
449478
return $this->groups->toArray();
450479
}
480+
481+
/**
482+
* @see \Serializable::serialize()
483+
*/
484+
public function serialize()
485+
{
486+
return serialize(array(
487+
$this->id,
488+
));
489+
}
490+
491+
/**
492+
* @see \Serializable::unserialize()
493+
*/
494+
public function unserialize($serialized)
495+
{
496+
list (
497+
$this->id,
498+
) = unserialize($serialized);
499+
}
451500
}
452501

453502
The ``AcmeUserBundle:Group`` entity class defines three table fields (``id``,

reference/forms/twig_reference.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ rendering forms. There are several different functions available, and each
99
is responsible for rendering a different part of a form (e.g. labels, errors,
1010
widgets, etc).
1111

12+
.. _reference-forms-twig-label:
13+
1214
form_label(form.name, label, variables)
1315
---------------------------------------
1416

@@ -26,6 +28,8 @@ label you want to display as the second argument.
2628
See ":ref:`twig-reference-form-variables`" to learn about the ``variables``
2729
argument.
2830

31+
.. _reference-forms-twig-errors:
32+
2933
form_errors(form.name)
3034
----------------------
3135

@@ -38,6 +42,8 @@ Renders any errors for the given field.
3842
{# render any "global" errors #}
3943
{{ form_errors(form) }}
4044
45+
.. _reference-forms-twig-widget:
46+
4147
form_widget(form.name, variables)
4248
---------------------------------
4349

@@ -59,6 +65,8 @@ rendering many fields at once (e.g. ``form_widget(form)``).
5965
See ":ref:`twig-reference-form-variables`" to learn more about the ``variables``
6066
argument.
6167

68+
.. _reference-forms-twig-row:
69+
6270
form_row(form.name, variables)
6371
------------------------------
6472

@@ -77,6 +85,8 @@ above.
7785
See ":ref:`twig-reference-form-variables`" to learn about the ``variables``
7886
argument.
7987

88+
.. _reference-forms-twig-rest:
89+
8090
form_rest(form, variables)
8191
--------------------------
8292

@@ -89,6 +99,8 @@ obvious (since it'll render the field for you).
8999
90100
{{ form_rest(form) }}
91101
102+
.. _reference-forms-twig-enctype:
103+
92104
form_enctype(form)
93105
------------------
94106

@@ -169,4 +181,5 @@ to see what options you have available.
169181
{# does **not** work - the variables are not recursive #}
170182
{{ form_widget(form, { 'attr': {'class': 'foo'} }) }}
171183
184+
172185
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/2.1/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

reference/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Reference Documents
1616
forms/types
1717
forms/twig_reference
1818

19+
twig_reference
20+
1921
constraints
2022
dic_tags
2123
requirements

reference/map.rst.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* :doc:`Validation Constraints Reference </reference/constraints>`
2121
* :doc:`Twig Template Function Reference</reference/forms/twig_reference>`
2222

23+
* :doc:`Twig Extensions (forms, filters, tags, etc) Reference</reference/twig_reference>`
24+
2325
* **Other Areas**
2426

2527
* :doc:`/reference/dic_tags`

0 commit comments

Comments
 (0)