【问题标题】:How to get the referer url in symfony redirection如何在 symfony 重定向中获取引用 url
【发布时间】:2012-08-12 09:50:34
【问题描述】:

我正在为一些 Web 应用程序使用 symfony 1.4。在那里,当有人尝试访问一个操作时,我将其重定向到一个新操作,如下所示。

//Assume I'm redecting from module1/action1 to module2/action2
$this->redirect('module2/action2');

我在 module2/action2 中可以获得重定向的 url。我用过

$request->getReferer();

但它没有给出任何结果。

我不需要使用 forward 而不是 redirect,因为它不符合我的需要。有人可以帮我解决这个问题。

【问题讨论】:

    标签: php url redirect symfony-1.4


    【解决方案1】:

    我可以建议您将引用者放在会话中,以便在重定向后能够检索。这个怎么sfGuardperform it

    重定向之前:

    // save the referer
    $referer = $this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer();
    $this->getUser()->setAttribute('referer', $referer);
    
    // make your redirect
    $this->redirect('module2/action2');
    

    然后,在您的 module2/action2 中,像这样检索您的推荐人:

    $referer = $this->getUser()->getAttribute('referer');
    
    // finally, remove it from session
    $this->getUser()->getAttributeHolder()->remove('referer');
    

    【讨论】:

    • 那么我们需要在哪里执行此操作。是在过滤器上还是在某个地方。
    • 不,你可以把一切都放在你的行动中
    • 是的,但是我们必须采取的每一个行动。它不会是我们可以参考的通用地方。
    • 用一个自定义的控制器扩展你的控制器
    猜你喜欢
    • 1970-01-01
    • 2011-03-22
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 2016-12-22
    • 1970-01-01
    相关资源
    最近更新 更多