Answer the question
In order to leave comments, you need to log in
What is a good practice for defining write access in Symfony 4?
Hello.
Access to pages in general is defined via security.yaml:
access_control:
- { path: ^/cp/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/cp/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/cp/forgot-password, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/console, roles: IS_AUTHENTICATED_FULLY }
/**
* @Route("/{item<[1-9]\d*>}", name="console_item")
*/
public function actionConsoleItem(Console $console)
{
return $this->render('console/console_item.html.twig', [
'console' => $console,
]);
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="id")
*/
private $user;
...
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
Answer the question
In order to leave comments, you need to log in
Maybe you can write directly in the controller?
if ($this->getUser()->getId() !== $console->getUser()->getId()) {
throw new UnauthorizedHttpException('Access denied');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question