php Laravel 4 - 使用参数重定向::路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18727693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 - Redirect::route with parameters
提问by Chris Campbell
Is it possible to specify a Redirect::route to a Resource Controller with parameters and specify how the parameters are handled?
是否可以使用参数指定 Redirect::route 到资源控制器并指定如何处理参数?
I have the following route defined:
我定义了以下路线:
Route::resource('account','AccountController');
Route::resource('account','AccountController');
In another route I want to be able to pass parameters to account.create with values acquired earlier so I can pre-populate the create form, but want them passed using as a POST request.
在另一条路线中,我希望能够将参数传递给 account.create 并使用之前获取的值,以便我可以预先填充创建表单,但希望它们作为 POST 请求传递。
Redirect::route('account.create',array('name' => $name));
Redirect::route('account.create',array('name' => $name));
The above works, but passes the parameters as a GET request.
以上工作,但将参数作为 GET 请求传递。
回答by Joseph Silber
Redirect::route('account.create')->with('name', $name);
This'll flash it to the session, which you would then retrieve after the redirect with Session::get('name')
.
这会将其闪存到会话中,然后您将在重定向后使用Session::get('name')
.