簡體   English   中英

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

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

我有一個 TestController 的視圖文件並在上面添加了評論表單(我的頁面所在頁面的 url 是 www.example.com/test/view/slug)現在評論表單發布在 url www.example.com /comments/add 操作評論在我寫的添加后添加成功(在評論/添加方法中)

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

我所期待的是它應該重定向到 www.example.com/test/view/slug 。 它在我的本地主機上的那個 url 上重定向但是當我部署我的應用程序時它正在重定向而不是重定向它正在重定向到 url www.example.com/comment/www.example.com 並給出錯誤

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

嘗試這個

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

這將在您的重定向中使用完整的 url,這可能會解決您將重定向添加到當前 URL 而不僅僅是使用它的問題。

你可以用這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM