diff --git a/best_practices/security.rst b/best_practices/security.rst index d2bb31f09b5..5e5d78e90aa 100644 --- a/best_practices/security.rst +++ b/best_practices/security.rst @@ -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(); // } - + // // ... } @@ -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 diff --git a/controller.rst b/controller.rst index 102ca934e3f..dec8b34dd99 100644 --- a/controller.rst +++ b/controller.rst @@ -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 ` -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 `) -and that it's :ref:`public `. - .. index:: single: Controller; Managing errors single: Controller; 404 pages diff --git a/doctrine/multiple_entity_managers.rst b/doctrine/multiple_entity_managers.rst index 78ddd96006d..bc958e0d0f9 100644 --- a/doctrine/multiple_entity_managers.rst +++ b/doctrine/multiple_entity_managers.rst @@ -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'); diff --git a/routing.rst b/routing.rst index 99a510504e9..b1a14956458 100644 --- a/routing.rst +++ b/routing.rst @@ -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' ));