Laravel redirect :: route在页面加载之间显示一条消息 [英] Laravel redirect::route is showing a message between page loads

查看:170
本文介绍了Laravel redirect :: route在页面加载之间显示一条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Laravel开发一个Web应用程序,并且该应用程序运行良好,直到最近.我不知道是什么触发了它,但这是我遇到的问题的摘要:

I'm currently developing a web app using Laravel, and the app was working perfectly fine until recently. I had no idea what triggered it but here's a summary of the issue I'm having:

登录通常可以正常工作,因为我有一个AccountController可以做到这一点:

Logging in used to work as I have an AccountController that does this:

$auth = Auth::attempt(array(
    'username' => Input::get('username'),
    'password' => Input::get('password'),
    'active'=>1);
if ($auth) {
     return Redirect::route('home');
}

return Redirect::route('account-sign-in');

原始路线如下:

Route::get('/', array('as'=>'home', 'use'=>'HomeController@show'));

成功登录后,该应用通常会立即返回首页.在我的home.blade.php文件中,我将放置一个@if(Auth::check())来确保一旦用户登录,主页将提供一组不同的文本.

The app would usually return to home page immediately upon successful login. And in my home.blade.php, I would have an @if(Auth::check()) in place to make sure that once a user is logged in, the home page would serve a different set of texts.

但是,最近,我注意到在提交登录请求后,中间页面显示了一条消息正在重定向到http://localhost.com/".在此之前,该消息不存在,并且错误随该消息一起开始显示.

Recently however, I noticed that after submitting a request to log in, there's an intermediate page showing a message "Redirecting to http://localhost.com/". The message was not there prior to this, and the errors started showing up along with this message.

我在网上查找了所有信息,有人建议源代码中存在换行/空格问题.我查看了我拥有的所有源代码,没有任何东西表明存在问题.

I looked up all the information I can online, and someone suggested that there were line break/space issues with the source code. I looked at all the source code I had and nothing would've suggested there's something wrong.

当时非常绝望,我删除了Redirect :: route('home'),而是将其替换为View :: make('home').这样就阻止了消息的显示,并且我能够再次照常登录.

Desperate at the time, I removed Redirect::route('home') and replaced that with View::make('home') instead. That stopped the message from showing up, and I'm able to login as usual again.

所以我有两个问题: 1)是什么引起这个奇怪的问题? 2)在这种情况下,使用View :: make()与Redirect :: route()有什么关系吗?

So I have two questions: 1) what is causing this odd issue? 2) is there anything wrong with using View::make() in this case vs Redirect::route()?

谢谢!

推荐答案

我花了整个周末来查找实际原因并解决此问题后,遇到了同样的问题.我找到了这个stackoverflow问题,并感到了与我的问题相同的问题.

I faced same issue and after spending my whole weekend to find actual cause and fix this issue. I landed on this stackoverflow question and felt its same issue as that of mine.

我使用了以下核心php函数进行重定向,而不是从控制器返回视图文件.

I used following core php function to redirect instead of returning a view file from controller.

header('Location: /');

打印出带有空白行的实际文件.删除此行解决了我的问题.

It printed actual file which had blank line. Removing this line fixed my problem.

我的代码库中有成千上万个文件.我的假设是,我尝试过使用不同的脚本在任何文件的开头查找这样的空行,并且根据这些脚本的结果,没有这样的文件.我假设我的任何文件中都没有空白行.但是header('Location:/')证明我的假设不正确,并且我在错误的行上工作.

There were thousands of files in my code base. My assumption was that I have tried different scripts to find such blank lines at start of any file and there was no such file as per those scripts results. I assumed there is is no blank line in any of my files. But header('Location: /') proved that my assumption was not correct and I was working on wrong lines.

这篇关于Laravel redirect :: route在页面加载之间显示一条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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