我有一个哨兵 laravel 4 设置。
此刻,对于个人资料视图,我应该像这样链接
http://localhost/ffdd/public/3/show
其中 3 是用户 ID
我正在使用以下路线
Route::get('/{profile}/show', array('as' => 'profile.show', 'uses' => 'ProfilesController@show'));
我需要相同的链接结果
http://localhost/ffdd/public/3
我应该改变什么路线。
并且对于将来,我希望这个用户 id 位置为 username 。
编辑 2
我目前的路线结构是这样的。
Route::get('/{userId?}', array('as' => 'profile', 'uses' => 'ProfilesController@index'));
Route::post('/{userId?}', array('as' => 'profile-koko', 'uses' => 'Controllers\Account\ProfileController@postIndex'));
Route::get('/{profile}/show', array('as' => 'profile.show', 'uses' => 'ProfilesController@show'));
当profilescontroller 的索引收到路由请求时,它只是将其转发给show 方法。
// User is logged in
$user = Sentry::getUser();
$user = $user->id;
//return View::make('profiles.index');
return Redirect::action('ProfilesController@show', array('userId'=>$user));
}
当我使用这个
Route::get('{profile}',array(
'as' => 'test2',
'uses' => 'ProfilesController@show',
));
正如我的朋友 itachi 在他的回复中所说!
我收到这个错误!
Some mandatory parameters are missing ("profile") to generate a URL for route "profile.show".
编辑 3
<?php
# Profile
Route::get('/{userId?}', array('as' => 'profile', 'uses' => 'ProfilesController@index'));
Route::post('/{userId?}', array('as' => 'profile-koko', 'uses' => 'Controllers\Account\ProfileController@postIndex'));
Route::resource('profile', 'ProfilesController@show');
Route::get('{profile}/show',array(
'as' => 'profile.show',
'uses' => 'ProfilesController@show',
));
Route::get('{profile}',array(
'as' => 'test2',
'uses' => 'ProfilesController@show',
));