XF 2.2 Inserting data into custom field via addon

mjda

Well-known member
I'm in the process of converting a site from vB to XF. Right now there is some user data from a custom vB add-on stored in its own table in the database. When I re-wrote the add-on to work on XF I used a custom profile field for that data. Now I need to find a way to get the data from the current db table into the profile field that I've set up for it.

Anyone who might can show me how to do that, or at least point me in the right direction?
 
It only took me about 6 hours, but I finally figured this one out. Here's how I did it, in case anyone else is trying to figure out how to do this:

PHP:
$user = $this->app->em()->find('XF:User', $userId, ['Profile']);
        
$user->Profile->custom_fields->set('field_id', $fieldValue);
$user->Profile->save();

This may not be "right", but it'll work.
 
Have you tried:

PHP:
$user->Profile->custom_fields['field_id'] = $someValue;
$user->save();
 
Have you tried:

PHP:
$user->Profile->custom_fields['field_id'] = $someValue;
$user->save();

I haven't. What I've got seems to be working just fine in my testing so I'll just roll with that. Thanks for the reply though.
 
Back
Top Bottom