Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit77f2876

Browse files
committed
minor#8986 Removed invalid examples (TheDevilOnLine, Tom Maaswinkel, javiereguiluz)
This PR was merged into the 4.0 branch.Discussion----------Removed invalid examplesTemplating isn't a service in Symfony 4+ (even after `composer req templating`), so probably we're looking for the twig service.The Router service isn't public and can therefor not be called from the container:```$ php bin/console debug:container router // This service is an alias for the service router.defaultInformation for Service "router.default"======================================== ---------------- ----------------------------------------------- Option Value ---------------- ----------------------------------------------- Service ID router.default Class Symfony\Bundle\FrameworkBundle\Routing\Router Tags - Calls setConfigCacheFactory Public no Synthetic no Lazy no Shared yes Abstract no Autowired no Autoconfigured no ---------------- -----------------------------------------------```Commits-------3492028 Use controller method injection instead of the constructorf9091b0 Updated documentation to reflect best practice of using Dependency Injection over Container. Includes changes from PR#898518e6d9e Removed "Accessing the Container Directly"89e38ef Removed invalid examples
2 parents81e8a4d +3492028 commit77f2876

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

‎best_practices/security.rst‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,20 @@ more advanced use-case, you can always do the same security check in PHP:
238238
// equivalent code without using the "denyAccessUnlessGranted()" shortcut:
239239
//
240240
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
241+
// use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
242+
//
243+
// ...
244+
//
245+
// public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
246+
// $this->authorizationChecker = $authorizationChecker;
247+
// }
248+
//
241249
// ...
242250
//
243-
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
251+
// if (!$this->authorizationChecker->isGranted('edit', $post)) {
244252
// throw $this->createAccessDeniedException();
245253
// }
246-
254+
//
247255
// ...
248256
}
249257
@@ -357,14 +365,22 @@ via the even easier shortcut in a controller:
357365
358366
$this->denyAccessUnlessGranted('edit', $post);
359367
360-
// or without the shortcut:
361-
//
362368
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
369+
// use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
370+
//
363371
// ...
364372
//
365-
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
373+
// public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
374+
// $this->authorizationChecker = $authorizationChecker;
375+
// }
376+
//
377+
// ...
378+
//
379+
// if (!$this->authorizationChecker->isGranted('edit', $post)) {
366380
// throw $this->createAccessDeniedException();
367381
// }
382+
//
383+
// ...
368384
}
369385
370386
Learn More

‎controller.rst‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -290,33 +290,6 @@ in your controllers.
290290

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

293-
.. _controller-access-services-directly:
294-
295-
Accessing the Container Directly
296-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297-
298-
If you extend the base ``Controller`` class, you can access:ref:`public services<container-public>`
299-
via the:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::get`
300-
method. Here are several common services you might need::
301-
302-
$templating = $this->get('templating');
303-
304-
$router = $this->get('router');
305-
306-
$mailer = $this->get('mailer');
307-
308-
// you can also fetch parameters
309-
$someParameter = $this->getParameter('some_parameter');
310-
311-
If you receive an error like:
312-
313-
..code-block::text
314-
315-
You have requested a non-existent service "my_service_id"
316-
317-
Check to make sure the service exists (use:ref:`debug:container<container-debug-container>`)
318-
and that it's:ref:`public<container-public>`.
319-
320293
..index::
321294
single: Controller; Managing errors
322295
single: Controller; 404 pages

‎doctrine/multiple_entity_managers.rst‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,14 @@ the default entity manager (i.e. ``default``) is returned::
231231

232232
// ...
233233

234+
use Doctrine\ORM\EntityManagerInterface;
235+
234236
class UserController extends Controller
235237
{
236-
public function indexAction()
238+
public function indexAction(EntityManagerInterface $em)
237239
{
238-
// All 3 return the "default" entity manager
240+
// These methods also return the default entity manager, but it's preferred
241+
// to get it by inyecting EntityManagerInterface in the action method
239242
$em = $this->getDoctrine()->getManager();
240243
$em = $this->getDoctrine()->getManager('default');
241244
$em = $this->get('doctrine.orm.default_entity_manager');

‎routing.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ Generating URLs with Query Strings
576576
The ``generate()`` method takes an array of wildcard values to generate the URI.
577577
But if you pass extra ones, they will be added to the URI as a query string::
578578

579-
$this->get('router')->generate('blog', array(
579+
$this->router->generate('blog', array(
580580
'page' => 2,
581581
'category' => 'Symfony'
582582
));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp