You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sebastian G. Marinescu edited this page Feb 22, 2016
·
2 revisions
An Example for an after-save hook.
This get's called when an item is added, useful if you want to update your position-field:
<?php
/**
* Set the last position on newly saved object
*/
// Get Object & Company
$object = & $modx->getOption('object',$scriptProperties,null);
$properties = $modx->getOption('scriptProperties',$scriptProperties,array());
$postvalues = $modx->getOption('postvalues',$scriptProperties,array());
if ($properties['object_id'] === 'new') {
// Ask for last position
$q = $modx->newQuery('Clients');
$q->select(array(
"max(position)",
));
$lastPosition = $modx->getValue($q->prepare());
// Set and Save
$object->set('position', ++$lastPosition);
$object->save();
}