Ok, there you have at least two options.
You can just reorder the fields each time you output the user data (simple solution but maybe a bit odd):
My recommendation is, to reorder the fields according to their position and save them in this order. So you'll have to loop through users and re-save the fields id's, but only once. Then you must delete this snippet (Perform a backup of the "/data/imanager" folder before execute the code!):
Now you can use your snippet as before:
You can just reorder the fields each time you output the user data (simple solution but maybe a bit odd):
PHP Code:
$userid = 1;
$imanager = imanager();
$user = $imanager->getItem('slug=Users', $userid);
$fieldMapper = new FieldMapper();
$fields = $fieldMapper->filterFields('position', 'ASC', (array) $user->fields);
foreach($fields as $field) {
...
My recommendation is, to reorder the fields according to their position and save them in this order. So you'll have to loop through users and re-save the fields id's, but only once. Then you must delete this snippet (Perform a backup of the "/data/imanager" folder before execute the code!):
PHP Code:
// Reorder item fields by position
$imanager = imanager();
$category = $imanager->getCategory('slug=Users');
$users = $imanager->getItems($category->id);
$fieldMapper = new FieldMapper();
foreach($users as $user) {
$fields = $fieldMapper->filterFields('position', 'ASC', (array) $user->fields);
foreach($fields as $field) {
$field->id = $field->position;
$field->save();
$user->fields->{$field->name}->id = $field->position;
}
$user->save();
}
Now you can use your snippet as before:
PHP Code:
// Dispalay user fields
$userid = 1;
$imanager = imanager();
$user = $imanager->getItem('slug=Users', $userid);
echo '<table>';
foreach ($user->fields as $data) {
if(isset($data->value))
{
echo '
<tr>
<td><strong>'.$data->label.': </strong></td>
<td>'.$data->value.'</td>
</tr>
';
}
}
echo '</table>';