简体   繁体   English

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

[英]cakePHP redirection with $this->referer() not working properly

I have one view file of TestController And on that I have added comment form (the url of page on which my page exist is www.example.com/test/view/slug)now comment form is posting on url www.example.com/comments/add action comment is adding successfully after addition I have written (in comment/add method)我有一个 TestController 的视图文件并在上面添加了评论表单(我的页面所在页面的 url 是 www.example.com/test/view/slug)现在评论表单发布在 url www.example.com /comments/add 操作评论在我写的添加后添加成功(在评论/添加方法中)

            $this->redirect($this->referer());

what I was expecting is it should redirect to www.example.com/test/view/slug .我所期待的是它应该重定向到 www.example.com/test/view/slug 。 its redirecting on that url on my localhost but when I deployed my application it is redirecting not redirecting propery it is redirecting on url www.example.com/comment/www.example.com and giving error它在我的本地主机上的那个 url 上重定向但是当我部署我的应用程序时它正在重定向而不是重定向它正在重定向到 url www.example.com/comment/www.example.com 并给出错误

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

Try this尝试这个

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

This will use FULL urls in your redirect and this may fix your problem with adding your redirect to the current URL instead of just using it.这将在您的重定向中使用完整的 url,这可能会解决您将重定向添加到当前 URL 而不仅仅是使用它的问题。

你可以用这个

$this->redirect($this->referer());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM