简单的redirect()函数在symfony 1.4中不起作用
我假设我在这里做了一些明显错误的事情,但我不知道是什么。我的代码非常简单:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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
我有类似的问题。我认为问题出在 $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.