Guest User

Untitled

a guest
Jan 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. $tv = $modx->getObject('modTemplateVar', array('name' => 'hitcount'));
  2.  
  3. $criteria = array(
  4. 'tmplvarid' => $tv->get('id'),
  5. 'contentid' => $modx->resourceIdentifier
  6. );
  7.  
  8. if(!$tvResource = $modx->getObject('modTemplateVarResource', $criteria)){
  9. $tvResource = $modx->newObject('modTemplateVarResource');
  10. $tvResource->set('value', 1);
  11. $tvResource->set('tmplvarid', $tv->get('id'));
  12. $tvResource->set('contentid', $modx->resourceIdentifier);
  13. $tvResource->save();
  14. } else {
  15. $value = (int)$tvResource->get('value') + 1;
  16. $tvResource->set('value', $value);
  17. $tvResource->save();
  18. }
Add Comment
Please, Sign In to add comment