If I understand you well you need a User Attribute. It will be saved automatically in the UserInfo
and if you set the options correctly it will be displayed on the user account page / add user page.
Note that all the following code should go in a Controller file in /application/controllers
or even better inside a package. How to create a package is well documented here. That way your site can be updated without any problems.
Your associative array with dynamic values from a DB table or other sources to be filled in the User Attribute (a Dropdown in this case):
$options = array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz'
);
Attributes parameters:
$selectArgs = array(
'akHandle' => 'my_select',
'akName' => t('my Select'), // t() is for translation
'uakProfileDisplay' => true, // Will be displayed on the Users Profile page
'uakMemberListDisplay' => true, // Will be displayed on the dashboard members page
'uakProfileEdit' => true, // A memeber is able to edit the attribute
'uakProfileEditRequired' => true, // The attribute MUST be filled with a value
'uakRegisterEdit' => true, // Will be displayed on the Register Page
'uakRegisterEditRequired' => true, // The attribute MUST be filled with a value upon registration
'akIsSearchableIndexed' => true, // The attribute will be indexed (searchable)
'akSelectAllowOtherValues' => false, // A user may add/remove other options to the select attribute
'akSelectOptionDisplayOrder' => 'alpha_asc', // the display order
'akIsSearchable' => true // one can search by these options
);
Classes used:
use \Concrete\Core\Attribute\Type as AttributeType;
use UserAttributeKey;
use Concrete\Attribute\Select\Option;
Define the Attribute Type:
$attrSelect = AttributeType::getByHandle('select');
Check if the Attribute already exists and if not, create it:
$mySelect = UserAttributeKey::getByHandle($selectArgs['akHandle'])
if(!is_object($mySelect)) {
UserAttributeKey::add($attrSelect, $selectArgs);
$mySelect = UserKey::getByHandle($args_address['akHandle']);
}
And finally fill the options into the select:
foreach($options as $value) {
Option::add($mySelect, t($value));
}