Hey all,
I would like to track number of views of each page, so i wrote:
class Page extends SiteTree {
public static $db = array(
'Viewed' => 'Int'
);
}
class Page_Controller extends ContentController {
public function init() {
parent::init();
if ($this->ID) {
if (!Session::get('Visited_'.$this->ID)) {
$page = DataObject::get_by_id('Page', $this->ID);
if ($page) {
$page->Viewed++;
$page->writeToStage("Stage");
$page->publish("Stage", "Live");
}
Session::set('Visited_'.$this->ID, true);
}
}
}
This solution works however i end up with huge amount of version copies (each for one view increment)
Is there any way to avoid versioning on save? Or is there a better solution?
Thanks,