Hi
I want user_id from username and email fields from modx_user table.
Have functionality for stripe payment in which i want user id using username and email fields from modx_user table.
Is there any way which is useful to me?
Arkalp.com
-
☆ A M B ☆
- 24,524 Posts
There are two tables, users and user_attributes. The user table has the username and password, while the user_attributes table has the email field.
The id of the user is the "id" field in the users table, and it's the internalKey field in the user_attributes table.
You can use the supplied MODX user placeholders and output modifiers if you don't need a snippet, it all depends on exactly how you are using this information:
http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-%28output-modifiers%29#InputandOutputFilters%28OutputModifiers%29-Chaining%28MultipleOutputFilters%29
If you need to get user data in code in a snippet, use the API:
http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.getuser
Thank you sottwell, It what i really need for my solutions.
Arkalp.com
It's not the fastest way, but for a payment, it's probably plenty fast enough:
$output = '';
$userId = 12;
$user = $modx->getObject('modUser', $userId);
if ($user) {
$username = $user->get('username');
$output .= '<br />Username: ' . $username;
$profile = $user->getOne('Profile');
if ($profile) {
$email = $profile->get('email');
$output .= '<br />Email: ' . $email;
} else {
$output .= '<br />Profile not found';
}
} else {
$output .= '<br />User Not Found';
}
return $output;