Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Auth package, how to save profile_fields
  • Hi guys,
    I saw that the Auth user model has a field named "profile_fields".
    I have tried to save there some information (name, surname and other) but I don't know how to do that.

    Some ideas or example to show me?

    Thanks!
  • HarroHarro
    Accepted Answer
    It depends.

    If you're using Simpleauth, profile_fields is a database column containing a serialized array. Anything you pass to update_user() that is not a valid column will be stored in that array, and you can use the get() method to get it our again. If you're using the ORM model, it will automatically unserialize it for you, so you can access the field as an array.

    If you're using Ormauth, profile_fields is not used, additional data is stored in the user metadata table, using EAV. You can access it using standard ORM object properties, any field name not in the user table will be assumed to be an EAV attribute.
  • Thanks Harro, I'll try :)
  • Hi Harro,
    I've tried the solution but I can't retrieve the "clear" data after updating the user.
    Here is my code:

    $user->get_profile_fields('screename');

    What I get is the complete field:

    a:1:{s:9:"screename";s:13:"Administrator";}

    and not the value "Administrator".

    Any idea?

    EDIT: found the problem --> I'm an idiot
  • I'm also an idiot ;)

    How did you 'fix'/access the unserialized data? Mine is returning a serialized data string as you described. I'm using Simpleauth, my User model is Model_User extending \Orm\Model - should I be using a different class?
  • If you're accessing the user table using an ORM model, you need to use the typing observer, and define the data type of the profile_fields column as "serialize".

    It will make sure the data will be converted to an array on read, and back to serialized form on write.
  • Nice one, I'll give it a go - cheers Harro! :)

Howdy, Stranger!

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

In this Discussion