Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
User Profile Fields Unserialize Error
  • Hi,

    I am trying to access user's profile fields which are hold as serialized data, but I am getting error.

    unserialize(): Error at offset 100 of 122 bytes

    Despite of I used Observer_Typing, I get the error always. 

    Here's my codes:
    protected static $_properties = array(
    'id',
    'username',
    'password',
            'email',
            'group',
            'profile_fields' => array(
                'data_type' => 'serialize',
            ),
            'last_login',
    'created_at',
            'login_hash',
    'created_at'
    );

    protected static $_observers = array(
    'Orm\Observer_CreatedAt' => array(
    'events' => array('before_insert'),
    'mysql_timestamp' => false,
    ),
            'Orm\\Observer_Typing' => array(
                'events' => array('before_save', 'after_save', 'after_load'),
            )
    );
  • Which version of Fuel, which Auth driver do you use, and what method do exactly call to get this error?
  • I am using Fuel 1.6 and Simpleauth. I couldn't use any call method yet. It is under Model_User, when I try the open homepage I encountered with the error. Model_User code is at the top. Thanks in advance. 
  • Is that your own model, or the model included in the Auth package (which is for Ormauth only)?

    The problem I think you have is that the Observer_Typing will not create an empty array for profile_fields that are NULL. An empty profile_fields column should contain "a:0:{}", which represents an empty array.

    How did you create the records that have a NULL value?
  • Thanks Harro. Most likely the error depends on how to create user. I created a user record by using Auth::create_user() on Oil. I tried to create simple serialize data and paste it profile_fields, Now, I am able to take the data as array successfully.

    I think Auth:create_user has mis configuration as it is creating user on Oil. Thanks again.
  • HarroHarro
    Accepted Answer
    create_user() indeed doesn't add it, Simpleauth has logic internally to deal with that. It was never made to be interacted with using a model.

    This should change, but that doesn't help you now (and all others already having an existing user table).

    I think the best option is to use Observer_Self, en create an after_load method that will convert the NULL value to array(). This should run after the Typing observer, as it will fail if it detects the array.
  • Just checked the code.

    The simpleauth driver does save a serialized array when you use create_user(). And as far as I can see from github history, it has always done so.

    So if you have NULL in your table, something weird is going on.
  • I added a few record by using create_user() and I am now getting successfully results. As you already said that something weird is going on. :) Thanks for your help.

Howdy, Stranger!

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

In this Discussion