Reputation: 15458
I want to use a placeholder from the Login plugin in an xPDO SQL query, eg:
$userid = [[+id]];
$sql = "SELECT * FROM `table` WHERE `id` = $userid";
$modx->query($sql);
However, if I echo the $userid
var I just get Array
.
Would anyone know the proper way of converting a ModX Placeholder into a PHP var?
Upvotes: 0
Views: 418
Reputation: 156
MeltingDog,
$modx->toPlaceholder() is the only function which used $modx->getPlaceholder() and only serves to search a placeholder array created by $modx->toPlaceholder() and $modx->toPlaceholders() calls via PHP snippets and classes.
What you wanted to do is described in the Login documentation via the $hook variable.
The user is available via the means Login is used: $userObject = $hook->getValue('register.user'); or $userObject = $hook->getValue('updateprofile.user');
In both cases the code would be completed thusly:
$userid = $user->getPrimaryKey();
or
$userid = $user->id;
or
$userid = $user->get('id');
Upvotes: 1