@@ -221,10 +221,6 @@ more advanced use-case, you can always do the same security check in PHP:
221
221
222
222
.. code-block :: php
223
223
224
- use Symfony\Component\Security\Core\Exception\AccessDeniedException;
225
-
226
- // ...
227
-
228
224
/**
229
225
* @Route("/{id}/edit", name="admin_post_edit")
230
226
*/
@@ -238,7 +234,16 @@ more advanced use-case, you can always do the same security check in PHP:
238
234
}
239
235
240
236
if (!$post->isAuthor($this->getUser())) {
241
- throw new AccessDeniedException();
237
+ $this->denyAccessUnlessGranted('edit', $post);
238
+
239
+ // or without the shortcut:
240
+ //
241
+ // use Symfony\Component\Security\Core\Exception\AccessDeniedException;
242
+ // ...
243
+ //
244
+ // if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
245
+ // throw $this->createAccessDeniedException();
246
+ // }
242
247
}
243
248
244
249
// ...
@@ -327,10 +332,6 @@ via the even easier shortcut in a controller:
327
332
328
333
.. code-block :: php
329
334
330
- use Symfony\Component\Security\Core\Exception\AccessDeniedException;
331
-
332
- // ...
333
-
334
335
/**
335
336
* @Route("/{id}/edit", name="admin_post_edit")
336
337
*/
@@ -342,6 +343,9 @@ via the even easier shortcut in a controller:
342
343
343
344
// or without the shortcut:
344
345
//
346
+ // use Symfony\Component\Security\Core\Exception\AccessDeniedException;
347
+ // ...
348
+ //
345
349
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
346
350
// throw $this->createAccessDeniedException();
347
351
// }
0 commit comments