Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel Input::flash()如何检索flash值_Flash_Laravel_Redirect_Input - Fatal编程技术网

Laravel Input::flash()如何检索flash值

Laravel Input::flash()如何检索flash值,flash,laravel,redirect,input,Flash,Laravel,Redirect,Input,这是我保存表单数据的代码 Route::any('test', function(){ if (Request::isMethod('post')){ //return Redirect::back()->withInput(); return Redirect::to('test2')->withInput(); } else { return View::make('home'); } }); Rou

这是我保存表单数据的代码

Route::any('test', function(){
    if (Request::isMethod('post')){
        //return Redirect::back()->withInput();
        return Redirect::to('test2')->withInput();
    }
    else {
        return View::make('home');
    }
});
Route::get('test2', function(){
    return var_dump(Input::all());  // Getting Empty Array here.
});
我只是用name='email'输入一条信息,然后发布。当重定向到另一个页面时,它不会使用
Redirect::to('test2')->withInput()转发输入



我很困惑,如何使用
Input::flash()
Redirect::to('test2')->withInput()

当您使用
重定向::to()->withInput()
时,它所做的是将
Input::all()
的当前状态放入会话变量中供以后访问(它不会重新提交输入或类似的内容)。因此,在新的重定向请求中,您不能使用
input:all()
(因为它没有重新发布)访问相同的输入,但现在它位于
input::old()
下。与flahs变量非常相似,它也只能用于一个请求,因此如果要重新刷新它,可能需要执行
Session::reflash()
,或者可以再次使用
->withInput()
(尽管我怀疑它,因为新的
Input::all()
是空的)

希望这是有道理的。基本上,“test2”路由需要使用
Input::old()


尽管如此,如果您将POST请求重定向到以后通过
Input::old()
,则可能是您做了一些不太正确的事情-这不是此构造的真正目的。当然,如果您只是在玩框架,那么您可以做任何您想做的事情。

当您使用
Redirect::to()->withInput()
时,它的作用是将
Input::all()
的当前状态放入会话变量中供以后访问(它不会重新提交输入或类似的内容)。因此,在新的重定向请求中,您不能使用
input:all()
(因为它没有重新发布)访问相同的输入,但现在它位于
input::old()
下。与flahs变量非常相似,它也只能用于一个请求,因此如果要重新刷新它,可能需要执行
Session::reflash()
,或者可以再次使用
->withInput()
(尽管我怀疑它,因为新的
Input::all()
是空的)

希望这是有道理的。基本上,“test2”路由需要使用
Input::old()

尽管如此,如果您将POST请求重定向到以后通过
Input::old()
,则可能是您做了一些不太正确的事情-这不是此构造的真正目的。当然,如果您只是在玩弄框架,那么您就可以随心所欲了。

示例:

Route::any('test', function(){
        if (Request::isMethod('post')){
            Input::flash();
            return Redirect::back();
            // return Redirect::back()->withInput();
        }
        else {
            if(Input::old('email'))return Input::old(); //::old is only accessible when we did ::flash() or ::withInput()
            return View::make('home');
    }
});
要检索错误等的表单数据,请使用

Input::old()   
而Input::old()如果没有

Redirect::back()->withInput()

详细信息作为注释附在代码中

示例:

Route::any('test', function(){
        if (Request::isMethod('post')){
            Input::flash();
            return Redirect::back();
            // return Redirect::back()->withInput();
        }
        else {
            if(Input::old('email'))return Input::old(); //::old is only accessible when we did ::flash() or ::withInput()
            return View::make('home');
    }
});
要检索错误等的表单数据,请使用

Input::old()   
而Input::old()如果没有

Redirect::back()->withInput()


详细信息作为注释附在代码中

您为我解释了答案,谢谢。我明白你说的话。您可以使用Redirect::to()->withInput()和Input::flash()修改您的答案吗。我不知道如何返回两个重定向::和视图::在单个路由中生成。非常感谢,很好的帮助。花了一点时间去理解,但还是做到了+很高兴能帮你找到自己的答案。你确实努力向我解释了答案,谢谢。我明白你说的话。您可以使用Redirect::to()->withInput()和Input::flash()修改您的答案吗。我不知道如何返回两个重定向::和视图::在单个路由中生成。非常感谢,很好的帮助。花了一点时间去理解,但还是做到了+很高兴能帮助你找到自己的答案。