8000 Added shortcut methods for controllers by Cydonia7 · Pull Request #4109 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Added shortcut methods for controllers #4109

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fixes
  • Loading branch information
Cydonia7 committed Jan 4, 2015
commit 0758d62968b3cfcbfc406004fa7c35971ef0c3fb
11 changes: 6 additions & 5 deletions book/security.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,23 @@ user to be logged in to access this URL:
Securing a Controller
~~~~~~~~~~~~~~~~~~~~~

Protecting your application based on URL patterns is easy, but may not be
fine-grained enough in certain cases. When necessary, you can easily force
authorization from inside a controller::

.. versionadded:: 2.6
The ``denyAccessUnlessGranted()`` method was introduced in Symfony 2.6. Previously (and
still now), you could check access directly and throw the ``AccessDeniedException`` as shown
in the example below).
Copy link
Member

Choose a reason for hiding this comment

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

I would move it above the paragraph (right below the "Securing a Controller" headline).


Protecting your application based on URL patterns is easy, but may not be
fine-grained enough in certain cases. When necessary, you can easily force
authorization from inside a controller::

// ...

public function helloAction($name)
{
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!');
Copy link
Member

Choose a reason for hiding this comment

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

Same thing - I'd like to show the "old" way (which would now use the security.authorization_checker service in 2.6) in a comment.

Copy link
Member

Choose a reason for hiding this comment

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

And we need a versionadded note above this:

.. versionadded:: 2.6
    The ``denyAccessUnlessGranted()`` method was introduced in Symfony 2.6. Previously (and
    still now), you could check access directly and throw the ``AccessDeniedException`` as shown
    in the example below).

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should add a brief explanation of the weird null middle argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right.


// The second parameter is used to specify on what object the role is tested.
//
// Old way :
// if (false === $this->get('security.authorization_checker')->isGranted( 8000 9;ROLE_ADMIN')) {
// throw $this->createAccessDeniedException('Unable to access this page!');
Expand Down Expand Up @@ -322,7 +324,6 @@ to users that have a specific role.
array('path' => '^/admin', 'role' => 'ROLE_ADMIN'),
),
));
>>>>>>> master

.. note::

Expand Down
1 change: 0 additions & 1 deletion quick_tour/the_controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ method::

The ``redirectToRoute()`` method takes as arguments the route name and an optional
array of parameters and redirects the user to the URL generated with those arguments.
>>>>>>> master

You can also internally forward the action to another action of the same or
different controller using the ``forward()`` method::
Expand Down
0