在symfony登录页面后保留POST参数 [英] retaining POST parameters after login page in symfony

查看:64
本文介绍了在symfony登录页面后保留POST参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使symfony在登录页面后保留POST数据?

how can i make symfony retain the POST data after login page?

例如,当用户填写表单时,cookie过期.提交表单后,用户将重定向到登录页面.成功登录后,他将获得重定向返回到表单的操作" URL,而没有来自初始表单的任何POST数据.

for example, the cookie was expired while user was filling the form. after submitting the form user gets a redirect to a login page. and after successful login he gets a redirect back to form's "action" url without any POST data from the initial form.

symfony中是否有任何机制可以处理这些数据,或者我必须编写自己的机制?

is there any mechanism in symfony to handle that data, or i have to write my own?

顺便说一句,我正在使用sfGuardPlugin

btw, i'm using sfGuardPlugin

推荐答案

我为此编写了一个简单的过滤器.也许您可以扩展其功能并可以使用,就在这里

I wrote a simple filter for that. Maybe you can extend its features and you can use, here it is

class postFilter extends sfFilter
{
    public function execute($filterChain)
  {
    // Execute this filter only once
    if ($this->isFirstCall())
    {
      // reach user object
      $user    = $this->getContext()->getUser();
      // request
      $request = $this->getContext()->getRequest();
      // if user unauthenticated and if user posted a form 
      if(!$user->isAuthenticated() AND $request->isMethod('post'))
      {
        // now you can save the post parameters
        $user->setAttribute('param_name', $request->getParameter('post_data'));
        // or something like that 
      }
    }

    // Execute next filter
    $filterChain->execute();
  }
}

并将您的过滤器添加到filters.yml

And add your filter to filters.yml

post_filter:
  class: postFilter

希望对您有帮助.

这篇关于在symfony登录页面后保留POST参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆