Laravel 4 如何使用laravel4将会话变量传递到视图中
我想将登录id传递到我的查看页面。我在用户登录提交功能中获得了id 实际上,我想在同一个控制器中的一个或多个函数中获取id。 如何在控制器中获取会话id。。 正常情况下,我这样做就够了 这是我的代码,任何人都可以查看并告诉我需要更改什么 控制器Laravel 4 如何使用laravel4将会话变量传递到视图中,laravel-4,Laravel 4,我想将登录id传递到我的查看页面。我在用户登录提交功能中获得了id 实际上,我想在同一个控制器中的一个或多个函数中获取id。 如何在控制器中获取会话id。。 正常情况下,我这样做就够了 这是我的代码,任何人都可以查看并告诉我需要更改什么 控制器 public function user_login_submits() { $inputs = Input::all(); $uname = Input::get('username
public function user_login_submits()
{
$inputs = Input::all();
$uname = Input::get('username');
$password = Input::get('password');
$logincheck=Userlogin::login_checks($uname,$password);
if($logincheck == 1)
{
$id=Session::get('customer_id');
return Redirect::to('businessprio/create_news?p=1');
}
else if($logincheck == 0)
{
//echo "fail";
return Redirect::to('businessprio/create');
}
}
型号
public static function login_checks($uname,$password)
{
$check = DB::table('customer_login')
->where('username','=',$uname)
->where('password','=',$password)->get();
if($check)
{
//Session::put(['customer_id'=>'value']);
Session::put('customer_id', $check[0]->customer_id);
Session::put('username', $check[0]->username);
return 1;
}
else
{
return 0;
}
}
我不会将其传递给模型,而是在控制器本身中进行
public function user_login_submits()
{
$uname = Input::get('username');
$password = Input::get('password');
$check = DB::table('customer_login')
->where('username','=',$uname)
->where('password','=',$password)->count();
if($check==1)
{
$id=Session::get('customer_id');
return Redirect::to('businessprio/create_news?p=1');
}
else
{
return Redirect::to('businessprio/create');
}
}
推荐:
但是我强烈建议您通过Auth::trunt来完成,也就是说,遵循干净的方法
public function user_login_submits()
{
if (Auth::attempt(['email' => $userEmail, 'password' => $userPassword])) {
return Redirect::to('businessprio/create_news?p=1');
}
else
{
return Redirect::to('businessprio/create');
}
}
如果这样做,则可以访问默认的身份验证用户检查
Auth::check()
通过获取登录的用户详细信息
Auth::user()->id
Auth::user()->username
注意:要使用默认的Auth::trunt
您也应该使用用户模型