我正在使用laravel。用于认证哨兵2。当用户访问我的网站时,他们会转到页面
http://dolovers.com/profile/13
这里13是用户id。
我正在研究通过用户名找到用户的更好程序
而且我还想减少链接:
http://dolovers.com/<username>
我该如何从sentry2和laravel开始。感谢您的帮助:)配置文件的路由:
# Profile
// Route::get('profile', array('as' => 'profile', 'uses' => 'Controllers'Account'ProfileController@getIndex'));
Route::get('profile', array('as' => 'profile', 'uses' => 'ProfilesController@index'));
Route::post('profile', 'Controllers'Account'ProfileController@postIndex');
这就是通过id:找到用户的方法
$user = Sentry::findUserById(13);
或登录
$user = Sentry::findUserByLogin('john.doe@example.com');
$user = Sentry::findUserByLogin('sagiruddin-mondal');
要减少您的链接,您需要编辑您的路线:
Route::get('/{userId}',
array(
'as' => 'user.find.get',
'uses' => 'ProfilesController@index'
)
);
Route::post('/{userId}',
array(
'as' => 'user.find.post',
'uses' => 'ProfilesController@postIndex'
)
);
Route::get('/',
array(
'as' => 'home',
'uses' => 'HomeController@index'
)
);
它应该让你使用这样的路线
http://dolovers.com/<userid>
还可以使用创建URL
URL::route('user.find.get', array(13));
URL::route('user.find.post', array(13));
我还定义了指向的第二条路线(回家)
http://dolovers.com/
您的UsersController看起来像:
class UsersController extends Controller {
protected function findUser($username)
{
if ( ! $user = Sentry::findUserByLogin('sagiruddin-mondal'))
{
return "user not found";
}
return $user->name;
}
}