简单的redirect()函数在symfony 1.4中不起作用

发布于 2024-11-19 04:58:25 字数 609 浏览 0 评论 0原文

我假设我在这里做了一些明显错误的事情,但我不知道是什么。我的代码非常简单:

public function executeForward(sfWebRequest $request)
{
  //redirect traffic that has landed here to either advertiser's or our own lander
  if ( rand(1, 100) > 50 )
  {
    $this->redirect( 'http://www.google.com', 404 );
  }
  else
  {
    $this->redirect( 'http://www.bing.com', 404 );
  }
}

我知道模板正在加载此操作,因为我可以在此操作中编写草率的代码,并且它会在我的浏览器中显示 500。最重要的是,这是基本路线:

forward_page:
  url:   /forward
  param: { module: static, action: forward }

对于为什么这行不通,你们的 symfony 大师是否有一个非常明显的答案?我非常感谢您朝正确的方向推动。

I am assuming I'm doing something blatantly wrong here, but I can't figure out what. My code is very simple:

public function executeForward(sfWebRequest $request)
{
  //redirect traffic that has landed here to either advertiser's or our own lander
  if ( rand(1, 100) > 50 )
  {
    $this->redirect( 'http://www.google.com', 404 );
  }
  else
  {
    $this->redirect( 'http://www.bing.com', 404 );
  }
}

I know the template is loading this action as I can write sloppy code in this action and it will 500 in my browser. On top of that, here is the basic route:

forward_page:
  url:   /forward
  param: { module: static, action: forward }

Do any of your symfony masters have a painfully obvious answer as to why this doesn't work? I'd greatly appreciate a nudge in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伏妖词 2024-11-26 04:58:25

404 是一个错误代码:http://en.wikipedia.org/wiki/HTTP_404
尝试302代码,它表示重定向。顺便说一下,这是该选项的默认值:
http://trac.symfony-project.org /browser/branches/1.4/lib/action/sfAction.class.php

404 is an error code : http://en.wikipedia.org/wiki/HTTP_404
Try a 302 code, it's indicate a redirection. BY the way, it's the default value of this option:
http://trac.symfony-project.org/browser/branches/1.4/lib/action/sfAction.class.php

诺曦 2024-11-26 04:58:25

我有类似的问题。我认为问题出在 $this->redirect 上。据我所知, $this->redirect 期望第一个参数是 symfony 路由。它不接受外部 URL。不确定我是否正确。

I have a similar issue. I think the problem is with $this->redirect. As far as I could understand, $this->redirect expects the first parameter to be a symfony route. It does not accept external URLs. Not sure I am correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文