使用$ this-> referer()的cakePHP重定向无法正常工作 [英] cakePHP redirection with $this->referer() not working properly

查看:151
本文介绍了使用$ this-> referer()的cakePHP重定向无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图文件TestController并且我已经添加了评论表单(我的网页存在的网页的网址是www.example.com/test/view/slug)now评论表单发布在url www。 example.com/comments/add操作注释添加成功后已写入(在注释/添加方法中)

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)

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

我希望它应该重定向到www.example.com/test/view/slug。它重定向在我的localhost的那个url,但是当我部署我的应用程序,它是重定向不重定向属性它是重定向在url www.example.com/comment/www.example.com并给出错误

what I was expecting is it should redirect to 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

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


推荐答案

尝试此

$ 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.

这篇关于使用$ this-> referer()的cakePHP重定向无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆