denyAccessUnlessGranted in controller multiple roles denyAccessUnlessGranted in controller multiple roles symfony symfony

denyAccessUnlessGranted in controller multiple roles


looking into the method shows how it works

protected function denyAccessUnlessGranted($attributes, $object = null, $message = 'Access Denied.'){    if (!$this->isGranted($attributes, $object)) {        throw $this->createAccessDeniedException($message);    }}

so you could easily adapt this to your case

in your controller sth. like:

if(!$this->isGranted('ROLE_EDIT', $item) && !$this->isGranted('ROLE_OTHER', $item)){    throw $this->createAccessDeniedException('not allowed');}


denyAccessUnlessGranted accepts an array of Role Names, so

$this->denyAccessUnlessGranted(['ROLE_EDIT', 'ROLE_ADMIN'], $item, 'You cannot edit this item.');

so, you should be able to pass all your roles.

Craig