2015-07-28 7 views
0

, поэтому я использую laravel 4.2. моя проблема в том, что я не могу повторить данные из моего маршрута перенаправления. как я могу получить к нему доступ правильно? Я попытался найти правильный ответ, но мне это не помогло.Не удается получить доступ к данным, переданным при перенаправлении

public function postLogin() 
     { 
       $timeIn = date('Y-m-d G:i:s'); 
       $userLog = New UserLog; 
       $userLog->username = Input::get('username'); 
       $userLog->time_in = $timeIn; 
       $userLog->save(); 
       $users = $userLog; 

       return Redirect::route('account') 
          ->with('users', $users); 

     } 

public function account(){ 
    $data = Session::get('users'); 
    var_dump($data); 
    echo $data->username;// this one throws an error 
    } 

Я вижу, что он имеет значения в var_dump ($ data).

object(__PHP_Incomplete_Class)[92] 
public '__PHP_Incomplete_Class_Name' => string 'UserLog' (length=7) 
public 'timestamps' => boolean false 
public 'table' => string 'userlogs' (length=8) 
protected 'connection' => null 
protected 'primaryKey' => string 'id' (length=2) 
protected 'perPage' => int 15 
public 'incrementing' => boolean true 
protected 'attributes' => 
array (size=3) 
    'username' => string 'user' (length=4) 
    'time_in' => string '2015-07-28 15:11:43' (length=19) 
    'id' => int 240 
protected 'original' => 
array (size=3) 
    'username' => string 'user' (length=4) 
    'time_in' => string '2015-07-28 15:11:43' (length=19) 
    'id' => int 240 

это мои маршруты файл

Route::get('/login', array(
    'uses' => '[email protected]', 
    'as' => 'login')     
    ); 

Route::post('/postLogin', array(
     'uses' => '[email protected]', 
     'as' => 'postLogin')    
     ); 

Route::get('/account', array(
     'uses' => '[email protected]', 
     'as' => 'account')   
     ); 

ответ

1

Я чувствовал, что я сделал огромный успех просто путем отображения данных, и проблемы вызывают у меня, чтобы получить ошибки является __PHP_Incomplete_Class, как вы можете видеть на моем var_dump ($ data) выше. Чтобы правильно получить данные $ data, мне нужно сначала выполнить его неэтериализацию, прежде чем обращаться к обычным способом. здесь я просто добавил одну строку кода, и все работает очень хорошо. благодаря этому сообщению unserializing.

public function account(){ 
$data = Session::get('users'); 
$data = unserialize(serialize($data)); //added code to unserialize the __PHP_Incomplete_Class 
var_dump($data); 
echo $data->username; 
} 

в моем var_dump ($ данных) __PHP_Incomplete_Class теперь ушел

object(UserLog)[143] 
    public 'timestamps' => boolean false 
    protected 'table' => string 'userlogs' (length=8) 
    protected 'connection' => null 
    protected 'primaryKey' => string 'id' (length=2) 
    protected 'perPage' => int 15 
    public 'incrementing' => boolean true 
    protected 'attributes' => 
    array (size=3) 
     'username' => string 'user' (length=4) 
     'time_in' => string '2015-07-28 19:57:08' (length=19) 
     'id' => int 276 
    protected 'original' => 
    array (size=3) 
     'username' => string 'user' (length=4) 
     'time_in' => string '2015-07-28 19:57:08' (length=19) 
     'id' => int 276 
Смежные вопросы