Skip to content

Commit 994ed3a

Browse files
committed
Little fixes
1 parent f807d14 commit 994ed3a

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

book/controller.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()``
441441

442442
.. versionadded:: 2.6
443443
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 below).
444+
could use ``redirect()`` and ``generateUrl()`` together for this (see the example above).
445445

446446
Or, if you want to redirect externally, just use ``redirect()`` and pass it the URL::
447447

@@ -455,17 +455,21 @@ perform a 301 (permanent) redirect, modify the second argument::
455455

456456
public function indexAction()
457457
{
458-
return $this->redirectToRoute('homepage', 301);
458+
return $this->redirectToRoute('homepage', array(), 301);
459459
}
460460

461461
.. tip::
462462

463-
The ``redirect()`` method is simply a shortcut that creates a ``Response``
464-
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::
465466

466467
use Symfony\Component\HttpFoundation\RedirectResponse;
467468

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

470474
.. index::
471475
single: Controller; Rendering templates

book/security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ You can easily deny access from inside a controller::
817817
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!');
818818

819819
// Old way :
820-
// if (false === $this->isGranted('ROLE_ADMIN')) {
820+
// if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
821821
// throw $this->createAccessDeniedException('Unable to access this page!');
822822
// }
823823

cookbook/security/securing_services.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
How to Secure any Service or Method in your Application
66
=======================================================
77

8-
In the security chapter, you can see how to :ref:`secure a controller <book-security-securing-controller>`
9-
by requesting the ``security.authorization_checker`` service from the Service Container
10-
and checking the current user's role::
8+
In the security chapter, you can see how to
9+
:ref:`secure a controller <book-security-securing-controller>` by requesting
10+
the ``security.authorization_checker`` service from the Service Container and
11+
checking the current user's role::
1112

1213
// ...
1314
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
@@ -19,21 +20,19 @@ and checking the current user's role::
1920
// ...
2021
}
2122

22-
You can also secure *any* service in a similar way by injecting the ``security.authorization_checker``
23+
You can also secure *any* service by injecting the ``security.authorization_checker``
2324
service into it. For a general introduction to injecting dependencies into
2425
services see the :doc:`/book/service_container` chapter of the book. For
2526
example, suppose you have a ``NewsletterManager`` class that sends out emails
26-
and you want to restrict its use to only users who have some ``ROLE_NEWSLETTER_ADMIN``
27-
role. Before you add security, the class looks something like this:
28-
29-
.. code-block:: php
27+
and you want to restrict its use to only users who have some
28+
``ROLE_NEWSLETTER_ADMIN`` role. Before you add security, the class looks
29+
something like this::
3030

3131
// src/AppBundle/Newsletter/NewsletterManager.php
3232
namespace AppBundle\Newsletter;
3333

3434
class NewsletterManager
3535
{
36-
3736
public function sendNewsletter()
3837
{
3938
// ... where you actually do the work
@@ -49,8 +48,9 @@ check, this is an ideal candidate for constructor injection, which guarantees
4948
that the authorization checker object will be available inside the ``NewsletterManager``
5049
class::
5150

52-
namespace AppBundle\Newsletter;
51+
// src/AppBundle/Newsletter/NewsletterManager.php
5352

53+
// ...
5454
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
5555

5656
class NewsletterManager

0 commit comments

Comments
 (0)