有没有办法从创建活动重定向到SonataAdminBundle中的listAction?
我需要它在拒绝访问时重定向用户。
$curUser = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();
if ($this->getSubject()->getId() && $this->getSubject()->getUser()) {
if ($this->getSubject()->getUser() != $curUser) {
REDIRECT HERE
}
}
答案 0 :(得分:2)
首先,您需要添加使用RedirectResponse类。
use Symfony\Component\HttpFoundation\RedirectResponse;
之后:
$curUser = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();
if ($this->getSubject()->getId() && $this->getSubject()->getUser()) {
if ($this->getSubject()->getUser() != $curUser) {
$redirection = new RedirectResponse($this->getConfigurationPool()->getContainer()->get('router')->generate('your_route_name'));
$redirection->send();
}
}