$user = $modx->getUser(); foreach ( $user as $key => $value ) { $placeholders[$key] .= $value; }
This question has been answered by BobRay. See the first response.
<p> Username: [[+username]]<br/> email: [[+email]]<br/> Full Name: [[+fullname]]<br/> etc. </p>
$users = $modx->getCollectionGraph('modUser', '{"Profile":{}}'); $output = "<h3>User List</h3>"; foreach($users as $user) { $fields = $user->toArray(); unset($fields['password'], $fields['cachepwd'], $fields['salt'], $fields['hash_class'] ); if ($user->Profile) { $fields = array_merge($user->Profile->toArray(), $fields); } $output .= $modx->getChunk('UserChunk', $fields); } return $output;
I'm not not clear what you're trying to do, but this might be what you want:
Create a Tpl chunk called UserChunk with the fields you want to show and some formatting:
<p> Username: [[+username]] email: [[+email]] Full Name: [[+fullname]] etc. </p>
Put this code in your snippet
$users = $modx->getCollectionGraph('modUser', '{"Profile":{}}'); $output = "<h3>User List</h3>"; foreach($users as $user) { $fields = $user->toArray(); unset($fields['password'], $fields['cachepwd'], $fields['salt'], $fields['hash_class'] ); if ($user->Profile) { $fields = array_merge($user->Profile->toArray(), $fields); } $output .= $modx->getChunk('UserChunk', $fields); } return $output;
[[!Profile]] <p>Username: [[+username]]</p> <p>Full Name: [[+fullname]]</p> <p>Email: [[+email]]</p>
$user = $modx->getObjectGraph('modUser', '{"Profile":{}}', $userId); fields = $user->toArray(); unset($fields['password'], $fields['cachepwd'], $fields['salt'], $fields['hash_class'] ); if ($user->Profile) { $fields = array_merge($user->Profile->toArray(), $fields); } $output .= $modx->getChunk('UserChunk', $fields);
Ah, sorry. That's way easier. Just use the Profile snippet (part of the Login package).
[[!Profile]] <p>Username: [[+username]]</p> <p>Full Name: [[+fullname]]</p> <p>Email: [[+email]]</p>
If you prefer to do it in code, it's just like my example above without the loop, and with getObjectGraph() instead of getCollectionGraph().
$user = $modx->getObjectGraph('modUser', '{"Profile":{}}', $userId); $fields = $user->toArray(); unset($fields['password'], $fields['cachepwd'], $fields['salt'], $fields['hash_class'] ); if ($user->Profile) { $fields = array_merge($user->Profile->toArray(), $fields); } $output .= $modx->getChunk('UserChunk', $fields);
Ah, sorry. That's way easier. Just use the Profile snippet (part of the Login package).
$user = $modx->getObjectGraph('modUser', '{"Profile":{}}', $userId);
$user = $modx->getObjectGraph('modUser', '{"Profile":{}}', $userId); $fields = $user->toArray(); unset($fields['password'], $fields['cachepwd'], $fields['salt'], $fields['hash_class'] ); if ($user->Profile) { $fields = array_merge($user->Profile->toArray(), $fields); } $modx->toPlaceholders($fields, 'fi'); return $modx->getChunk('UserChunk');
You might look at ClassExtender for storing the extra user information.
To set placeholders with a prefix:
$user = $modx->getObjectGraph('modUser', '{"Profile":{}}', $userId); $fields = $user->toArray(); unset($fields['password'], $fields['cachepwd'], $fields['salt'], $fields['hash_class'] ); if ($user->Profile) { $fields = array_merge($user->Profile->toArray(), $fields); } $modx->toPlaceholders($fields, 'fi'); return $modx->getChunk('UserChunk');
You can do whatever you want with the $fields array before calling toPlaceholders().