Symfony3 提交后需要刷新

Symfony3 Need to refresh after submit

我希望提交表单后不刷新我的页面。

我使用重定向再次询问实体的列表,但是有没有变化,我还需要刷新。 我在其他表单上遇到了同样的问题,但重定向解决了它。

public function handleClient($client)
{
    if (!$client->getNom() || !$this->clientForm->isSubmitted() || !$this->clientForm->isValid())
        return;

    $this->getDoctrine()->getManager()->persist($client);
    $this->getDoctrine()->getManager()->flush();

    // HANDLE REFRESH LIST OF CLIENT EXPECTED
    $repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
    $this->listClients = $repository->getAllClientInverse();

    $this->redirect($this->generateUrl('accueil'));
}


public function clientAction(Request $request)
{
    // ACCUEIL
    $repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
    $this->listClients = $repository->getAllClientInverse();

    // HANDLE CLIENT CREATION AND REQUEST
    $this->clientLogicHandler();

    $repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
    $this->listClients = $repository->getAllClientInverse();

    return $this->render('CommonBundle:Default:index.html.twig',
        array('listClients' => $this->listClients)
        );
    }
}

编辑: 我发现问题是我直接调用视图而没有从控制器重新加载。有没有办法调用控制器来呈现新资源?

事实上,重定向只对动作起作用,对子函数不起作用。 我只需要对动作进行级联,并在需要时进行重定向,例如:

public function handleClient($client)
{
    if (!$client->getNom() || !$this->clientForm->isSubmitted() || !$this->clientForm->isValid())
        return false;

    $this->getDoctrine()->getManager()->persist($client);
    $this->getDoctrine()->getManager()->flush();

    // HANDLE REFRESH LIST OF CLIENT EXPECTED
    $repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
    $this->listClients = $repository->getAllClientInverse();

    $this->redirect($this->generateUrl('accueil'));
    return true;
}


public function clientAction(Request $request)
{
    // ACCUEIL
    $repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
    $this->listClients = $repository->getAllClientInverse();

    // HANDLE CLIENT CREATION AND REQUEST
   if ($this->handleClient())
        $this->redirect($this->generateUrl('accueil'));

    $repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
    $this->listClients = $repository->getAllClientInverse();

    return $this->render('CommonBundle:Default:index.html.twig',
        array('listClients' => $this->listClients)
        );
    }
}