【发布时间】:2014-02-27 09:50:27
【问题描述】:
我这里有个大问题,不知道怎么解决。
routes.php:
Route::group(array('prefix' => 'user'), function() {
Route::post('/{user}/{char_name}/selectedok', array(
'as' => 'char-profile-post',
'uses' => 'ProfileController@postDropDownList'
));
Route::get('/{user}/{char_name}/selectedok', array(
'as' => 'char-profile-get',
'uses' => 'ProfileController@getDropDownList'
));
});
ProfileController.php:
public function getDropDownList() {
return View::make('layout.profile');
}
public function postDropDownList($user, $char_name) {
if (Auth::check())
{
$user = Auth::user();
$selected_char = Input::get('choose');
$char_name = User::find($user->id)->characters()->where('char_name', '=', $selected_char)->first();
return Redirect::route('char-profile-get', array($user->username, $char_name->char_dynasty, $char_name->char_name))
->with('user', $user->username)
->with('charname', $char_name->char_name)
->with('dynastyname', $char_name->char_dynasty);
}
}
是的,我知道我使用 3 个参数重定向到 char-profile-get,但我只需要 2 个。它不会打扰我。如您所见,我使用->with 重定向。我将在视图中打印数据的唯一方法是在视图中执行此操作:
你选择的角色是
{{ Session::get('charname') }} {{ Session::get('dynastyname')}}
如果我不覆盖postDropDownList($user, $char_name) 中的变量,我的URL 将看起来像这样:
http://localhost/CaughtMiddle/tutorial/public/index.php/user/%7Buser%7D/%7Bchar_name%7D/selectedok
而不是这个:
http://localhost/CaughtMiddle/tutorial/public/index.php/user/SerbanSpire/Spirescu/selectedok?Serban
所以判决。函数中的参数永远不会收到任何数据。我什至不知道如何描述它们,函数的参数为空,即使我使用正确的数据重定向到 get 路由。 var_dump($user) 或 var_dump($char_name) 不会在浏览器上打印任何内容,dd($user) 和 dd($char_name) 也不会打印任何内容,print_r() 也不会。
我的解决方案可行吗?通过使用->with 重定向并将数据存储在会话中?因为这个解决方案会驱使我大量使用Session::get(),每次我使用数据库中的信息,但我不更新它!如果我错了,请阻止我。
为什么路径中的变量没有转到我的函数的参数?如果我的函数没有任何参数,则代码将相同。基本上,这些参数是没有用的。
【问题讨论】: