File tree Expand file tree Collapse file tree 3 files changed +34
-7
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +34
-7
lines changed
Original file line number Diff line number Diff line change @@ -238,12 +238,20 @@ more advanced use-case, you can always do the same security check in PHP:
238
238
// equivalent code without using the "denyAccessUnlessGranted()" shortcut:
239
239
//
240
240
// 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
+ //
241
249
// ...
242
250
//
243
- // if (!$this->get('security.authorization_checker') ->isGranted('edit', $post)) {
251
+ // if (!$this->authorizationChecker ->isGranted('edit', $post)) {
244
252
// throw $this->createAccessDeniedException();
245
253
// }
246
-
254
+ //
247
255
// ...
248
256
}
249
257
@@ -357,14 +365,22 @@ via the even easier shortcut in a controller:
357
365
358
366
$this->denyAccessUnlessGranted('edit', $post);
359
367
360
- // or without the shortcut:
361
- //
362
368
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
369
+ // use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
370
+ //
363
371
// ...
364
372
//
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)) {
366
380
// throw $this->createAccessDeniedException();
367
381
// }
382
+ //
383
+ // ...
368
384
}
369
385
370
386
Learn More
Original file line number Diff line number Diff line change @@ -231,11 +231,22 @@ the default entity manager (i.e. ``default``) is returned::
231
231
232
232
// ...
233
233
234
+ use Doctrine\ORM\EntityManagerInterface;
235
+
234
236
class UserController extends Controller
235
237
{
238
+ protected $em;
239
+
240
+ public function __construct(EntityManagerInterface $em)
241
+ {
242
+ $this->em = $em;
243
+ }
244
+
236
245
public function indexAction()
237
246
{
238
- // All 3 return the "default" entity manager
247
+ // All 4 return the "default" entity manager, though using
248
+ // dependency injection is a best practice
249
+ $em = $this->em;
239
250
$em = $this->getDoctrine()->getManager();
240
251
$em = $this->getDoctrine()->getManager('default');
241
252
$em = $this->get('doctrine.orm.default_entity_manager');
Original file line number Diff line number Diff line change @@ -576,7 +576,7 @@ Generating URLs with Query Strings
576
576
The ``generate() `` method takes an array of wildcard values to generate the URI.
577
577
But if you pass extra ones, they will be added to the URI as a query string::
578
578
579
- $this->get(' router') ->generate('blog', array(
579
+ $this->router->generate('blog', array(
580
580
'page' => 2,
581
581
'category' => 'Symfony'
582
582
));
You can’t perform that action at this time.
0 commit comments