Yii2重定向导致空白页面 [英] Yii2 redirect causes blank page

查看:80
本文介绍了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重定向导致空白页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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