cakePHP重定向与$ this-> referer()无法正常工作

时间:2014-01-31 11:29:52

标签: php cakephp

我有一个TestController的视图文件并且我已经添加了评论表单(我的页面存在的页面的网址是www.example.com/test/view/slug)现在评论表单在网址www上发布。我添加了(在评论/添加方法中)

之后添加了example.com/comments/add动作评论
            $this->redirect($this->referer());

我期待的是它应该重定向到www.example.com/test/view/slug。它重定向到我本地主机上的网址,但是当我部署我的应用程序时,重定向不重定向它正在重定向到网址www.example.com/comment/www.example.com并给出错误

Error: The requested address '/comments/www.example.com' was not found on this server.

1 个答案:

答案 0 :(得分:10)

试试这个

$this->redirect( Router::url( $this->referer(), true ) );

这将在您的重定向中使用完整的网址,这可能会解决您将重定向添加到当前网址而不是仅使用它的问题。

相关问题