我认为你必须遵循这个结构:
案例:提交表单页面后重定向到注册/登录页面。
1.) 填写表单并在提交表单后将发布数据转换为序列化数组。在这里。
2.)将该序列化数组粘贴到隐藏字段或会话(注册/登录页面)中。
3.) 填写注册表,注册后,发回上一个表单页面,将隐藏数据发送到该页面并反序列化它们。这里
建议:如果您希望您的帖子数据不显示在页面中,那么您可以使用 urlencode 和 urldecode 函数或您可以使用的任何其他编码方法。
注意:使用会话或 cookie 将帖子数据从一页发送到另一页是不好的做法。它将在所有页面上,直到您取消设置/删除它。
手动从控制器重定向到登录页面,使用以下:
$session->set('_security.user_firewall.target_path', $request->getUri());
throw new AuthenticationException(); // use Symfony\Component\Security\Core\Exception\AuthenticationException;
从注册页面重定向,使用以下内容:
$key = '_security.user_firewall.target_path'; #where "user_firewall" is your firewall name
//check if the referrer session key has been set
if ($this->container->get('session')->has($key))
{
//set the url based on the link they were trying to access before being authenticated
$url = $this->container->get('session')->get($key);
//remove the session key
$this->container->get('session')->remove($key);
}
// if the referrer key was never set, redirect to a default route
else{
$url = $this->generateUrl($routeName);
}
return new RedirectResponse($url);