Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can Session Retain Object?
  • Hello.
    I Wont To Retain Object By Session. 

    (1) Get Model_AdminClass By SQL. 

    $admin_login = \DB::select('*')->from('admins')
    ->where('account', '=', $account)
    ->and_where('password', '=', $password)
    ->execute()->current();

    (2) Set Model_Object to Session.

    \Session::set('admin_login', $admin_login);

    (3) Get Model_Object from Session.

    print_R( \Session::get('admin_login') );

    (4) Result

    __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => Admin\Model_Admin.....


    Now I Cannot Get Object Data From Session.
    How To Set Object? Help Me.
  • Storing custom objects in the session is quite complicated.

    You get "PHP_Incomplete_Class Object" if you try to deserialize an object, but the class isn't know (isn't loaded).

    So you need to load Model_Object before the session variable gets deserialized. And if the object has loaded relations, you need to make sure all those objects are loaded too.

    Unfortunately PHP doesn't do autoloading on unserialization.
  • There's no real need to store the object in this case - why don't you just store the ID of the retrieved record and then re-retrieve it whenever you need it on a different page load?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion