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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:06:18  来源:igfitidea点击:

Laravel 4 - Redirect::route with parameters

phplaravel

提问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').

回答by Alwin Kesler

Another extra info

另一个额外信息

You can't (o should not?) use dots in config session cookie's var. I had thoubles with this before. If you are having issues with this go check this value.

您不能(不应该?)在配置会话 cookie 的 var 中使用点。我以前有过这个。如果您对此有疑问,请检查此值。

Refer to this linkfor more information.

有关更多信息,请参阅此链接