Yii2重定向导致空白页面

编程入门 行业动态 更新时间:2024-10-26 10:39:08
本文介绍了Yii2重定向导致空白页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有任何服务器/主机设置可能导致 Yii2 中的简单重定向不起作用?

Is there any server/hosting setting that could cause simple redirect in Yii2 to not work?

例如:

function actionIndex(){ return $this->redirect('other-page'); }

此代码以空白页结束,没有显示任何错误或消息(错误报告已开启),响应代码为 200(尽管 Yii2 调试器显示 302).我网站上的一切正常,但只要代码到达任何 ->redirect(),它就会以空白页面结束.

This code ends up with a blank page, no errors or messages are displayed(Error reporting is on), response code is 200 (although Yii2 debugger shows 302). Everything on my website works fine but as soon as code reaches any ->redirect() it just end up with blank page.

这只发生在我的客户共享主机上(在我的本地机器和开发共享主机上一切正常).Yii2 运行时日志没有显示任何错误,也没有我的主机允许我访问的服务器日志.

This happens only on my clients shared hosting (on my local machine and development shared hosting everything works just fine). Yii2 runtime logs does not show any errors, neither server logs that my hosting is giving me access to.

推荐答案

原来这是标准的白页错误:在 php 文件的开头添加了新的空白行.我逐行浏览了框架文件.当我注释掉 if(headers_sent()) {return;} 时,Yii 终于抛出了一个异常,只是让我发现我的一个配置文件在文件的开头有额外的新行.删除它解决了问题.

It turned out that this was standard white page error: additional new blank line at the beginning of a php file. I went through framework files, line by line. When I commented out if(headers_sent()) {return;} Yii finally threw an exception, only to let me find out that one of my config files had extra new line at the beginning of the file. Removing it fixed the problem.

更多推荐

Yii2重定向导致空白页面

本文发布于:2023-11-01 19:51:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   空白   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!