Symfony - Sonata Admin - 从FormField重定向到List

时间:2017-02-13 14:05:49

标签: symfony sonata-admin

有没有办法从创建活动重定向到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
        }
    }

1 个答案:

答案 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();
    }
}