Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b46a025

Browse filesBrowse files
committed
Merge branch '2.0' into 2.1
Conflicts: reference/forms/types/collection.rst reference/twig_reference.rst
2 parents 6a21206 + dcfdfa3 commit b46a025
Copy full SHA for b46a025
Expand file treeCollapse file tree

38 files changed

+189
-150
lines changed

‎book/controller.rst

Copy file name to clipboardExpand all lines: book/controller.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ This controller is pretty straightforward:
119119

120120
* *line 4*: Symfony2 takes advantage of PHP 5.3 namespace functionality to
121121
namespace the entire controller class. The ``use`` keyword imports the
122-
``Response`` class, which our controller must return.
122+
``Response`` class, which the controller must return.
123123

124124
* *line 6*: The class name is the concatenation of a name for the controller
125125
class (i.e. ``Hello``) and the word ``Controller``. This is a convention
@@ -218,7 +218,7 @@ passed to that method::
218218
}
219219

220220
The controller has a single argument, ``$name``, which corresponds to the
221-
``{name}`` parameter from the matched route (``ryan`` in our example). In
221+
``{name}`` parameter from the matched route (``ryan`` in the example). In
222222
fact, when executing your controller, Symfony2 matches each argument of
223223
the controller with a parameter from the matched route. Take the following
224224
example:

‎book/from_flat_php_to_symfony2.rst

Copy file name to clipboardExpand all lines: book/from_flat_php_to_symfony2.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ is known as a "controller". The term :term:`controller` is a word you'll hear
131131
a lot, regardless of the language or framework you use. It refers simply
132132
to the area of *your* code that processes user input and prepares the response.
133133

134-
In this case, our controller prepares data from the database and then includes
134+
In this case, the controller prepares data from the database and then includes
135135
a template to present that data. With the controller isolated, you could
136136
easily change *just* the template file if you needed to render the blog
137137
entries in some other format (e.g. ``list.json.php`` for JSON format).

‎book/http_cache.rst

Copy file name to clipboardExpand all lines: book/http_cache.rst
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ on a cache to store and return "fresh" responses.
413413

414414
The HTTP specification defines a simple but powerful language in which
415415
clients and servers can communicate. As a web developer, the request-response
416-
model of the specification dominates our work. Unfortunately, the actual
416+
model of the specification dominates your work. Unfortunately, the actual
417417
specification document - `RFC 2616`_ - can be difficult to read.
418418

419419
There is an on-going effort (`HTTP Bis`_) to rewrite the RFC 2616. It does
@@ -553,8 +553,7 @@ would return. An ``ETag`` is like a fingerprint and is used to quickly compare
553553
if two different versions of a resource are equivalent. Like fingerprints,
554554
each ``ETag`` must be unique across all representations of the same resource.
555555

556-
Let's walk through a simple implementation that generates the ETag as the
557-
md5 of the content::
556+
To see a simple implementation, generate the ETag as the md5 of the content::
558557

559558
public function indexAction()
560559
{
@@ -871,7 +870,7 @@ independent of the rest of the page.
871870
}
872871
873872
In this example, the full-page cache has a lifetime of ten minutes.
874-
Next, let's include the news ticker in the template by embedding an action.
873+
Next, include the news ticker in the template by embedding an action.
875874
This is done via the ``render`` helper (See :ref:`templating-embedding-controller`
876875
for more details).
877876

@@ -892,7 +891,7 @@ By setting ``standalone`` to ``true``, you tell Symfony2 that the action
892891
should be rendered as an ESI tag. You might be wondering why you would want to
893892
use a helper instead of just writing the ESI tag yourself. That's because
894893
using a helper makes your application work even if there is no gateway cache
895-
installed. Let's see how it works.
894+
installed.
896895

897896
When standalone is ``false`` (the default), Symfony2 merges the included page
898897
content within the main one before sending the response to the client. But

‎book/http_fundamentals.rst

Copy file name to clipboardExpand all lines: book/http_fundamentals.rst
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ from the xkcd web server:
118118
:align: center
119119

120120
Translated into HTTP, the response sent back to the browser will look something
121-
like this:
121+
like this:
122122

123123
.. code-block:: text
124124
@@ -145,7 +145,7 @@ known as HTTP headers. For example, one important HTTP response header is
145145
``Content-Type``. The body of the same resource could be returned in multiple
146146
different formats like HTML, XML, or JSON and the ``Content-Type`` header uses
147147
Internet Media Types like ``text/html`` to tell the client which format is
148-
being returned. A list of common media types can be found on Wikipedia's
148+
being returned. A list of common media types can be found on Wikipedia's
149149
`List of common media types`_ article.
150150

151151
Many other headers exist, some of which are very powerful. For example, certain
@@ -259,17 +259,17 @@ the user is connecting via a secured connection (i.e. ``https``).
259259
:method:`Symfony\\Component\\HttpFoundation\\ParameterBag::all` and more.
260260
In fact, every public property used in the previous example is some instance
261261
of the ParameterBag.
262-
262+
263263
.. _book-fundamentals-attributes:
264-
264+
265265
The Request class also has a public ``attributes`` property, which holds
266266
special data related to how the application works internally. For the
267267
Symfony2 framework, the ``attributes`` holds the values returned by the
268268
matched route, like ``_controller``, ``id`` (if you have an ``{id}``
269269
wildcard), and even the name of the matched route (``_route``). The
270270
``attributes`` property exists entirely to be a place where you can
271271
prepare and store context-specific information about the request.
272-
272+
273273

274274
Symfony also provides a ``Response`` class: a simple PHP representation of
275275
an HTTP response message. This allows your application to use an object-oriented
@@ -400,7 +400,7 @@ with many other tools Symfony makes available - to create and return a ``Respons
400400
object. In other words, the controller is where *your* code goes: it's where
401401
you interpret the request and create a response.
402402

403-
It's that easy! Let's review:
403+
It's that easy! To review:
404404

405405
* Each request executes a front controller file;
406406

@@ -413,7 +413,7 @@ It's that easy! Let's review:
413413
A Symfony Request in Action
414414
~~~~~~~~~~~~~~~~~~~~~~~~~~~
415415

416-
Without diving into too much detail, let's see this process in action. Suppose
416+
Without diving into too much detail, here is this process in action. Suppose
417417
you want to add a ``/contact`` page to your Symfony application. First, start
418418
by adding an entry for ``/contact`` to your routing configuration file:
419419

@@ -465,14 +465,14 @@ specific PHP method ``contactAction`` inside a class called ``MainController``::
465465
}
466466
}
467467

468-
In this very simple example, the controller simply creates a
469-
:class:`Symfony\\Component\\HttpFoundation\\Response` object with the HTML
468+
In this very simple example, the controller simply creates a
469+
:class:`Symfony\\Component\\HttpFoundation\\Response` object with the HTML
470470
"``<h1>Contact us!</h1>"``. In the :doc:`controller chapter</book/controller>`,
471471
you'll learn how a controller can render templates, allowing your "presentation"
472472
code (i.e. anything that actually writes out HTML) to live in a separate
473473
template file. This frees up the controller to worry only about the hard
474474
stuff: interacting with the database, handling submitted data, or sending
475-
email messages.
475+
email messages.
476476

477477
Symfony2: Build your App, not your Tools.
478478
-----------------------------------------

‎book/page_creation.rst

Copy file name to clipboardExpand all lines: book/page_creation.rst
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ HTTP response.
2222
Symfony2 follows this philosophy and provides you with tools and conventions
2323
to keep your application organized as it grows in users and complexity.
2424

25-
Sounds simple enough? Let's dive in!
26-
2725
.. index::
2826
single: Page creation; Example
2927

3028
The "Hello Symfony!" Page
3129
-------------------------
3230

33-
Let's start with a spin off of the classic "Hello World!" application. When
31+
Start by building a spin-off of the classic "Hello World!" application. When
3432
you're finished, the user will be able to get a personal greeting (e.g. "Hello Symfony")
3533
by going to the following URL:
3634

@@ -347,7 +345,7 @@ controller, and ``index.html.twig`` the template:
347345
348346
Hello <?php echo $view->escape($name) ?>!
349347
350-
Let's step through the Twig template line-by-line:
348+
Step through the Twig template line-by-line:
351349

352350
* *line 2*: The ``extends`` token defines a parent template. The template
353351
explicitly defines a layout file inside of which it will be placed.

‎book/propel.rst

Copy file name to clipboardExpand all lines: book/propel.rst
+31-31Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Databases and Propel
55
====================
66

7-
Let's face it, one of the most common and challenging tasks for any application
7+
One of the most common and challenging tasks for any application
88
involves persisting and reading information to and from a database. Symfony2
99
does not come integrated with any ORMs but the Propel integration is easy.
1010
To get started, read `Working With Symfony2`_.
@@ -18,8 +18,8 @@ persist it to the database and fetch it back out.
1818
.. sidebar:: Code along with the example
1919

2020
If you want to follow along with the example in this chapter, create an
21-
``AcmeStoreBundle`` via:
22-
21+
``AcmeStoreBundle`` via:
22+
2323
.. code-block:: bash
2424
2525
$ php app/console generate:bundle --namespace=Acme/StoreBundle
@@ -171,19 +171,19 @@ Fetching Objects from the Database
171171
Fetching an object back from the database is even easier. For example, suppose
172172
you've configured a route to display a specific ``Product`` based on its ``id``
173173
value::
174-
174+
175175
// ...
176176
use Acme\StoreBundle\Model\ProductQuery;
177-
177+
178178
public function showAction($id)
179179
{
180180
$product = ProductQuery::create()
181181
->findPk($id);
182-
182+
183183
if (!$product) {
184184
throw $this->createNotFoundException('No product found for id '.$id);
185185
}
186-
186+
187187
// ... do something, like pass the $product object into a template
188188
}
189189

@@ -192,22 +192,22 @@ Updating an Object
192192

193193
Once you've fetched an object from Propel, updating it is easy. Suppose you
194194
have a route that maps a product id to an update action in a controller::
195-
195+
196196
// ...
197197
use Acme\StoreBundle\Model\ProductQuery;
198-
198+
199199
public function updateAction($id)
200200
{
201201
$product = ProductQuery::create()
202202
->findPk($id);
203-
203+
204204
if (!$product) {
205205
throw $this->createNotFoundException('No product found for id '.$id);
206206
}
207-
207+
208208
$product->setName('New product name!');
209209
$product->save();
210-
210+
211211
return $this->redirect($this->generateUrl('homepage'));
212212
}
213213

@@ -227,12 +227,12 @@ method on the object::
227227

228228
Querying for Objects
229229
--------------------
230-
230+
231231
Propel provides generated ``Query`` classes to run both basic and complex queries
232232
without any work::
233-
233+
234234
\Acme\StoreBundle\Model\ProductQuery::create()->findPk($id);
235-
235+
236236
\Acme\StoreBundle\Model\ProductQuery::create()
237237
->filterByName('Foo')
238238
->findOne();
@@ -287,13 +287,13 @@ Start by adding the ``category`` definition in your ``schema.xml``:
287287
<column name="name" type="varchar" primaryString="true" size="100" />
288288
<column name="price" type="decimal" />
289289
<column name="description" type="longvarchar" />
290-
290+
291291
<column name="category_id" type="integer" />
292292
<foreign-key foreignTable="category">
293293
<reference local="category_id" foreign="id" />
294294
</foreign-key>
295295
</table>
296-
296+
297297
<table name="category">
298298
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
299299
<column name="name" type="varchar" primaryString="true" size="100" />
@@ -320,29 +320,29 @@ Your database has been updated, you can continue to write your application.
320320
Saving Related Objects
321321
~~~~~~~~~~~~~~~~~~~~~~
322322

323-
Now, let's see the code in action. Imagine you're inside a controller::
323+
Now, try the code in action. Imagine you're inside a controller::
324324

325325
// ...
326326
use Acme\StoreBundle\Model\Category;
327327
use Acme\StoreBundle\Model\Product;
328328
use Symfony\Component\HttpFoundation\Response;
329-
329+
330330
class DefaultController extends Controller
331331
{
332332
public function createProductAction()
333333
{
334334
$category = new Category();
335335
$category->setName('Main Products');
336-
336+
337337
$product = new Product();
338338
$product->setName('Foo');
339339
$product->setPrice(19.99);
340340
// relate this product to the category
341341
$product->setCategory($category);
342-
342+
343343
// save the whole
344344
$product->save();
345-
345+
346346
return new Response(
347347
'Created product id: '.$product->getId().' and category id: '.$category->getId()
348348
);
@@ -363,15 +363,15 @@ before. First, fetch a ``$product`` object and then access its related
363363

364364
// ...
365365
use Acme\StoreBundle\Model\ProductQuery;
366-
366+
367367
public function showAction($id)
368368
{
369369
$product = ProductQuery::create()
370370
->joinWithCategory()
371371
->findPk($id);
372-
372+
373373
$categoryName = $product->getCategory()->getName();
374-
374+
375375
// ...
376376
}
377377

@@ -395,7 +395,7 @@ inserted, updated, deleted, etc).
395395
To add a hook, just add a new method to the object class::
396396

397397
// src/Acme/StoreBundle/Model/Product.php
398-
398+
399399
// ...
400400
class Product extends BaseProduct
401401
{
@@ -429,8 +429,8 @@ Commands
429429

430430
You should read the dedicated section for `Propel commands in Symfony2`_.
431431

432-
.. _`Working With Symfony2`: http://www.propelorm.org/cookbook/symfony2/working-with-symfony2.html#installation
433-
.. _`Working With Symfony2 - Configuration`: http://www.propelorm.org/cookbook/symfony2/working-with-symfony2.html#configuration
434-
.. _`Relationships`: http://www.propelorm.org/documentation/04-relationships.html
435-
.. _`Behaviors reference section`: http://www.propelorm.org/documentation/#behaviors_reference
436-
.. _`Propel commands in Symfony2`: http://www.propelorm.org/cookbook/symfony2/working-with-symfony2#the_commands
432+
.. _`Working With Symfony2`: http://propelorm.org/cookbook/symfony2/working-with-symfony2.html#installation
433+
.. _`Working With Symfony2 - Configuration`: http://propelorm.org/cookbook/symfony2/working-with-symfony2.html#configuration
434+
.. _`Relationships`: http://propelorm.org/documentation/04-relationships.html
435+
.. _`Behaviors reference section`: http://propelorm.org/documentation/#behaviors_reference
436+
.. _`Propel commands in Symfony2`: http://propelorm.org/cookbook/symfony2/working-with-symfony2#the_commands

‎book/security.rst

Copy file name to clipboardExpand all lines: book/security.rst
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ perform a certain action.
2020
.. image:: /images/book/security_authentication_authorization.png
2121
:align: center
2222

23-
Since the best way to learn is to see an example, let's dive right in.
23+
Since the best way to learn is to see an example, start by securing your
24+
application with HTTP Basic authentication.
2425

2526
.. note::
2627

@@ -1701,6 +1702,24 @@ To switch back to the original user, use the special ``_exit`` username:
17011702
17021703
http://example.com/somewhere?_switch_user=_exit
17031704
1705+
During impersonation, the user is provided with a special role called
1706+
``ROLE_PREVIOUS_ADMIN``. In a template, for instance, this role can be used
1707+
to show a link to exit impersonation:
1708+
1709+
.. configuration-block::
1710+
1711+
.. code-block:: html+jinja
1712+
1713+
{% if is_granted('ROLE_PREVIOUS_ADMIN') %}
1714+
<a href="{{ path('homepage', {_switch_user: '_exit'}) }}">Exit impersonation</a>
1715+
{% endif %}
1716+
1717+
.. code-block:: html+php
1718+
1719+
<?php if ($view['security']->isGranted('ROLE_PREVIOUS_ADMIN')): ?>
1720+
<a href="<?php echo $view['router']->generate('homepage', array('_switch_user' => '_exit') ?>">Exit impersonation</a>
1721+
<?php endif; ?>
1722+
17041723
Of course, this feature needs to be made available to a small group of users.
17051724
By default, access is restricted to users having the ``ROLE_ALLOWED_TO_SWITCH``
17061725
role. The name of this role can be modified via the ``role`` setting. For

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.