Laravel 4.2 session :: get()方法不返回控制器中的会话数据

时间:2014-09-12 13:02:42

标签: php session laravel

嗨帮助我,

登录代码

         public function store()
          {
             $credentials = array(
            'u_email' =>  Input::get('email'),
            'password' =>  Input::get('password'));


           if (Auth::attempt($credentials) ) {

            $user = Auth::user()->toArray();
            $userrole = with(new User)->get_user_role($user['u_id']);

            $userobj['u_id']        =   $user['u_id'];
            $userobj['u_shortcode'] =   $user['u_shortcode'];
            $userobj['utype']       =   $user['utype'];
            $userobj['u_title']     =   $user['u_title'];
            $userobj['u_fname']     =   $user['u_fname'];
            $userobj['u_lname']     =   $user['u_lname'];
            $userobj['u_email']     =   $user['u_email'];
            $userobj['u_role']      =   $userrole;
            $userobj['id']          =   Session::getId();

            Session::put('admin', $userobj);
            $value = Session::get('admin');


            return Response::json([
                    'user' => $userobj ],
                202
            );

        }else{
            return Response::json([
                    'flash2' => 'Authentication failed'],
                202
            );
        }
}

我的第二个控制器是:

       public function get_sessionobj()
       {

        var_dump(Session::all());
        $value = Session::get('admin');
        print_r($value);
        exit();
      }

当我在登录后呼叫第二个控制器时,会话数据未打印。在登录控制器Session :: get(' admin')函数返回数据。我正在使用文件驱动程序进行会话存储。我看到我的会话文件有一些这样的数据:

   a:5:{s:6:"_token";s:40:"XrUgs7QLPlXvjvyzFaTdmDpqGL0aSZRzkJS0il9f";s:38:"login_82e5d2c56bdd0811318f0cf078b78bfc";s:1:"1";s:5:"admin";a:9:{s:4:"u_id";s:1:"1";s:11:"u_shortcode";s:5:"u1001";s:5:"utype";s:1:"1";s:7:"u_title";s:3:"Mr.";s:7:"u_fname";s:6:"Aristo";s:7:"u_lname";s:5:"Singh";s:7:"u_email";s:24:"chandan.singh@jetwave.in";s:6:"u_role";a:3:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"3";}s:2:"id";s:40:"cd074f7f61fcc88b3d92c482e57e8a12dc888958";}s:9:"_sf2_meta";a:3:{s:1:"u";i:1410525787;s:1:"c";i:1410525787;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}

1 个答案:

答案 0 :(得分:0)

在商店功能

中调用函数get_sessionobj()

示例:

public function store(){
  $this->get_sessionobj();
}