Created
September 20, 2011 11:55
-
-
Save digibutt/1228932 to your computer and use it in GitHub Desktop.
Log a hit in a plugin in MODX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tv = $modx->getObject('modTemplateVar', array('name' => 'hitcount')); | |
$criteria = array( | |
'tmplvarid' => $tv->get('id'), | |
'contentid' => $modx->resourceIdentifier | |
); | |
if(!$tvResource = $modx->getObject('modTemplateVarResource', $criteria)){ | |
$tvResource = $modx->newObject('modTemplateVarResource'); | |
$tvResource->set('value', 1); | |
$tvResource->set('tmplvarid', $tv->get('id')); | |
$tvResource->set('contentid', $modx->resourceIdentifier); | |
$tvResource->save(); | |
} else { | |
$value = (int)$tvResource->get('value') + 1; | |
$tvResource->set('value', $value); | |
$tvResource->save(); | |
} |
hehe, perhaps!
Thanks for sharing ^^
I suppose this is either onWebPreRender / OnWebInit and that it really doesn't matter much as long as it only triggers one on page review and has a resource. :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On review I think $tv->setValue($modx->resourceIdentifier, $value); would have been a little more elegant... =P