【问题标题】:Symfony - Sonata Admin - Redirect from FormField to ListSymfony - Sonata Admin - 从 FormField 重定向到列表
【发布时间】:2017-02-13 14:05:49
【问题描述】:

有没有办法在 SonataAdminBundle 中从 createAction 重定向到 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
        }
    }

【问题讨论】:

    标签: symfony sonata-admin


    【解决方案1】:

    首先你需要添加使用 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();
        }
    }
    

    【讨论】:

    • 嘿@Fatih Kahveci,谢谢 - 有没有办法从这个表格中获取奏鸣曲列表路线?
    • @cRsakaWolf 我不确定,但您无法在表单中找到列表路线名称。但是您可以使用 debug:router 命令轻松找到并找到您想要的任何路由名称。
    猜你喜欢
    • 2015-09-05
    • 2018-01-27
    • 1970-01-01
    • 2015-11-06
    • 2023-04-01
    • 2017-03-19
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多