Question

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?

Was it helpful?

Solution

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');

OTHER TIPS

I found it:

$userid = $modx->getPlaceholder('id');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top