Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Removed invalid examples #8986

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

Merged
merged 4 commits into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 21 additions & 5 deletions best_practices/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,20 @@ more advanced use-case, you can always do the same security check in PHP:
// equivalent code without using the "denyAccessUnlessGranted()" shortcut:
//
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
// use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
//
// ...
//
// public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
// $this->authorizationChecker = $authorizationChecker;
// }
//
// ...
//
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
// if (!$this->authorizationChecker->isGranted('edit', $post)) {
// throw $this->createAccessDeniedException();
// }

//
// ...
}

Expand Down Expand Up @@ -357,14 +365,22 @@ via the even easier shortcut in a controller:

$this->denyAccessUnlessGranted('edit', $post);

// or without the shortcut:
//
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
// use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
//
// ...
//
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
// public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
// $this->authorizationChecker = $authorizationChecker;
// }
//
// ...
//
// if (!$this->authorizationChecker->isGranted('edit', $post)) {
// throw $this->createAccessDeniedException();
// }
//
// ...
}

Learn More
Expand Down
27 changes: 0 additions & 27 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,33 +290,6 @@ in your controllers.

For more information about services, see the :doc:`/service_container` article.

.. _controller-access-services-directly:

Accessing the Container Directly
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you extend the base ``Controller`` class, you can access :ref:`public services <container-public>`
via the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::get`
method. Here are several common services you might need::

$templating = $this->get('templating');

$router = $this->get('router');

$mailer = $this->get('mailer');

// you can also fetch parameters
$someParameter = $this->getParameter('some_parameter');

If you receive an error like:

.. code-block:: text

You have requested a non-existent service "my_service_id"

Check to make sure the service exists (use :ref:`debug:container <container-debug-container>`)
and that it's :ref:`public <container-public>`.

.. index::
single: Controller; Managing errors
single: Controller; 404 pages
Expand Down
7 changes: 5 additions & 2 deletions doctrine/multiple_entity_managers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,14 @@ the default entity manager (i.e. ``default``) is returned::

// ...

use Doctrine\ORM\EntityManagerInterface;

class UserController extends Controller
{
public function indexAction()
public function indexAction(EntityManagerInterface $em)
{
// All 3 return the "default" entity manager
// These methods also return the default entity manager, but it's preferred
// to get it by inyecting EntityManagerInterface in the action method
$em = $this->getDoctrine()->getManager();
$em = $this->getDoctrine()->getManager('default');
$em = $this->get('doctrine.orm.default_entity_manager');
Expand Down
2 changes: 1 addition & 1 deletion routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ Generating URLs with Query Strings
The ``generate()`` method takes an array of wildcard values to generate the URI.
But if you pass extra ones, they will be added to the URI as a query string::

$this->get('router')->generate('blog', array(
$this->router->generate('blog', array(
'page' => 2,
'category' => 'Symfony'
));
Expand Down