Skip to content

Commit f24c84f

Browse files
committed
Merge branch '2.7'
* 2.7: (103 commits) Backporting some stuff from 2.7, that I think must have gotten merged only there by accident [#5064] Minor language tweaks Fixing bad merge conflict (forgot to save!) Remove unnecessary component reference Correct RegisterListenersPass namespace Fix service id Switched the first example to a static constructor method added some more components for Tobion as a merger Fixed variable name in : Reference -> validation constraints -> count -> basic usage -> PHP [#5036] Typo fix (probably mine originally) caught by xabbuh reword to serves Adding a link to define "lts" Better wording Minor improvement for symfony-installer with LTS Updating for new security service names in 2.6 [#5033] Tweaking variable name to "match" the service id [#5017] Minor language tweaks [#5015] Updating the security service name for 2.6 - thanks to Cordoval [#5015] Very small tweak [#5011] Adding one more fix I missed ...
2 parents feb621b + 1fccbf6 commit f24c84f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+756
-245
lines changed

book/controller.rst

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -429,35 +429,47 @@ A great way to see the core functionality in action is to look in the
429429
Redirecting
430430
~~~~~~~~~~~
431431

432-
If you want to redirect the user to another page, use the
433-
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::redirect`
434-
method::
432+
If you want to redirect the user to another page, use the ``redirectToRoute()`` method::
435433

436434
public function indexAction()
437435
{
438-
return $this->redirect($this->generateUrl('homepage'));
436+
return $this->redirectToRoute('homepage');
437+
438+
// redirectToRoute is equivalent to using redirect() and generateUrl() together:
439+
// return $this->redirect($this->generateUrl('homepage'), 301);
439440
}
440441

441-
The ``generateUrl()`` method is just a helper function that generates the URL
442-
for a given route. For more information, see the :doc:`Routing </book/routing>`
443-
chapter.
442+
.. versionadded:: 2.6
443+
The ``redirectToRoute()`` method was added in Symfony 2.6. Previously (and still now), you
444+
could use ``redirect()`` and ``generateUrl()`` together for this (see the example above).
445+
446+
Or, if you want to redirect externally, just use ``redirect()`` and pass it the URL::
447+
448+
public function indexAction()
449+
{
450+
return $this->redirect('http://symfony.com/doc');
451+
}
444452

445-
By default, the ``redirect()`` method performs a 302 (temporary) redirect. To
453+
By default, the ``redirectToRoute()`` method performs a 302 (temporary) redirect. To
446454
perform a 301 (permanent) redirect, modify the second argument::
447455

448456
public function indexAction()
449457
{
450-
return $this->redirect($this->generateUrl('homepage'), 301);
458+
return $this->redirectToRoute('homepage', array(), 301);
451459
}
452460

453461
.. tip::
454462

455-
The ``redirect()`` method is simply a shortcut that creates a ``Response``
456-
object that specializes in redirecting the user. It's equivalent to::
463+
The ``redirectToRoute()`` method is simply a shortcut that creates a
464+
``Response`` object that specializes in redirecting the user. It's
465+
equivalent to::
457466

458467
use Symfony\Component\HttpFoundation\RedirectResponse;
459468

460-
return new RedirectResponse($this->generateUrl('homepage'));
469+
public function indexAction()
470+
{
471+
return new RedirectResponse($this->generateUrl('homepage'));
472+
}
461473

462474
.. index::
463475
single: Controller; Rendering templates
@@ -623,12 +635,14 @@ For example, imagine you're processing a form submit::
623635
if ($form->isValid()) {
624636
// do some sort of processing
625637

626-
$request->getSession()->getFlashBag()->add(
638+
$this->addFlash(
627639
'notice',
628640
'Your changes were saved!'
629641
);
630642

631-
return $this->redirect($this->generateUrl(...));
643+
// $this->addFlash is equivalent to $this->get('session')->getFlashBag()->add
644+
645+
return $this->redirectToRoute(...);
632646
}
633647

634648
return $this->render(...);
@@ -638,8 +652,8 @@ After processing the request, the controller sets a ``notice`` flash message
638652
in the session and then redirects. The name (``notice``) isn't significant -
639653
it's just something you invent and reference next.
640654

641-
In the template of the next page (or even better, in your base layout template),
642-
the following code will render the ``notice`` message:
655+
In the template of the next action, the following code could be used to render
656+
the ``notice`` message:
643657

644658
.. configuration-block::
645659

book/doctrine.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ you have a route that maps a product id to an update action in a controller::
667667
$product->setName('New product name!');
668668
$em->flush();
669669

670-
return $this->redirect($this->generateUrl('homepage'));
670+
return $this->redirectToRoute('homepage');
671671
}
672672

673673
Updating an object involves just three steps:
@@ -778,6 +778,8 @@ entities (the topic of :ref:`relations <book-doctrine-relations>` will be
778778
covered later), group, etc. For more information, see the official
779779
`Doctrine Query Language`_ documentation.
780780

781+
.. _book-doctrine-custom-repository-classes:
782+
781783
Custom Repository Classes
782784
~~~~~~~~~~~~~~~~~~~~~~~~~
783785

book/forms.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ controller::
234234
if ($form->isValid()) {
235235
// perform some action, such as saving the task to the database
236236

237-
return $this->redirect($this->generateUrl('task_success'));
237+
return $this->redirectToRoute('task_success');
238238
}
239239

240240
// ...
@@ -319,7 +319,7 @@ querying if the "Save and add" button was clicked::
319319
? 'task_new'
320320
: 'task_success';
321321

322-
return $this->redirect($this->generateUrl($nextAction));
322+
return $this->redirectToRoute($nextAction);
323323
}
324324

325325
.. index::
@@ -1237,7 +1237,7 @@ it after a form submission can be done when the form is valid::
12371237
$em->persist($task);
12381238
$em->flush();
12391239

1240-
return $this->redirect($this->generateUrl('task_success'));
1240+
return $this->redirectToRoute('task_success');
12411241
}
12421242

12431243
If, for some reason, you don't have access to your original ``$task`` object,

book/http_cache.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ kernel::
166166
The caching kernel will immediately act as a reverse proxy - caching responses
167167
from your application and returning them to the client.
168168

169+
.. caution::
170+
171+
If you're using the :ref:`framework.http_method_override <configuration-framework-http_method_override>`
172+
option to read the HTTP method from a ``_method`` parameter, see the
173+
above link for a tweak you need to make.
174+
169175
.. tip::
170176

171177
The cache kernel has a special ``getLog()`` method that returns a string

book/installation.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ number as the second argument of the ``new`` command:
9898
# Windows
9999
c:\projects\> php symfony.phar new my_project_name 2.3.23
100100
101+
If you want your project to be based on the latest :ref:`Symfony LTS version <releases-lts>`,
102+
pass ``lts`` as the second argument of the ``new`` command:
103+
104+
.. code-block:: bash
105+
106+
# Linux, Mac OS X
107+
$ symfony new my_project_name lts
108+
109+
# Windows
110+
c:\projects\> php symfony.phar new my_project_name lts
111+
101112
Read the :doc:`Symfony Release process </contributing/community/releases>`
102113
to better understand why there are several Symfony versions and which one
103114
to use for your projects.

book/performance.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Use a Byte Code Cache (e.g. APC)
1818
One of the best (and easiest) things that you should do to improve your performance
1919
is to use a "byte code cache". The idea of a byte code cache is to remove
2020
the need to constantly recompile the PHP source code. There are a number of
21-
`byte code caches`_ available, some of which are open source. The most widely
22-
used byte code cache is probably `APC`_
21+
`byte code caches`_ available, some of which are open source. As of PHP 5.5,
22+
PHP comes with `OPcache`_ built-in. For older versions, the most widely used
23+
byte code cache is probably `APC`_
2324

2425
Using a byte code cache really has no downside, and Symfony has been architected
2526
to perform really well in this type of environment.
@@ -139,6 +140,7 @@ feature is disabled in the byte code cache (e.g. ``apc.stat=0`` in APC), there
139140
is no longer a reason to use a bootstrap file.
140141

141142
.. _`byte code caches`: http://en.wikipedia.org/wiki/List_of_PHP_accelerators
143+
.. _`OPcache`: http://php.net/manual/en/book.opcache.php
142144
.. _`APC`: http://php.net/manual/en/book.apc.php
143145
.. _`autoload.php`: https://github.com/symfony/symfony-standard/blob/master/app/autoload.php
144146
.. _`bootstrap file`: https://github.com/sensio/SensioDistributionBundle/blob/master/Composer/ScriptHandler.php

book/propel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ have a route that maps a product id to an update action in a controller::
244244
$product->setName('New product name!');
245245
$product->save();
246246

247-
return $this->redirect($this->generateUrl('homepage'));
247+
return $this->redirectToRoute('homepage');
248248
}
249249
}
250250

book/routing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The route is simple:
4545
class BlogController extends Controller
4646
{
4747
/**
48-
* @Route("/blog/{slug}")
48+
* @Route("/blog/{slug}", name="blog_show")
4949
*/
5050
public function showAction($slug)
5151
{

book/security.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -813,20 +813,29 @@ You can easily deny access from inside a controller::
813813

814814
public function helloAction($name)
815815
{
816-
if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
817-
throw $this->createAccessDeniedException();
818-
}
816+
// The second parameter is used to specify on what object the role is tested.
817+
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!');
818+
819+
// Old way :
820+
// if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
821+
// throw $this->createAccessDeniedException('Unable to access this page!');
822+
// }
819823

820824
// ...
821825
}
822826

823827
.. versionadded:: 2.6
824-
The ``security.authorization_checker`` service was introduced in Symfony 2.6. Prior
825-
to Symfony 2.6, you had to use the ``isGranted()`` method of the ``security.context`` service.
828+
The ``denyAccessUnlessGranted()`` method was introduced in Symfony 2.6. Previously (and
829+
still now), you could check access directly and throw the ``AccessDeniedException`` as shown
830+
in the example above).
831+
832+
.. versionadded:: 2.6
833+
The ``security.authorization_checker`` service was introduced in Symfony 2.6. Prior
834+
to Symfony 2.6, you had to use the ``isGranted()`` method of the ``security.context`` service.
826835

827-
The :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::createAccessDeniedException`
828-
method creates a special :class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
829-
object, which ultimately triggers a 403 HTTP response inside Symfony.
836+
In both cases, a special
837+
:class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
838+
is thrown, which ultimately triggers a 403 HTTP response inside Symfony.
830839

831840
That's it! If the user isn't logged in yet, they will be asked to login (e.g.
832841
redirected to the login page). If they *are* logged in, they'll be shown

book/testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ or perform more complex requests. Some useful examples::
394394
array('photo' => $photo)
395395
);
396396

397-
// Perform a DELETE requests and pass HTTP headers
397+
// Perform a DELETE request and pass HTTP headers
398398
$client->request(
399399
'DELETE',
400400
'/post/12',

book/validation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ workflow looks like the following from inside a controller::
232232
if ($form->isValid()) {
233233
// the validation passed, do something with the $author object
234234

235-
return $this->redirect($this->generateUrl(...));
235+
return $this->redirectToRoute(...);
236236
}
237237

238238
return $this->render('author/form.html.twig', array(

components/asset/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Asset
2+
=====
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
introduction

0 commit comments

Comments
 (0)