I programmed a hit counter for my blog. I always wondered if anyone reads my blog posts ;-) Now I know for sure.
May be this is useful to anyone else.
This is the method (BlogEntry_Controller.php):
function incViews() {
if(Session::get('BlogViewed-' . $this->ID) == false){
Session::set('BlogViewed-' . $this->ID, 'true');
$this->Views++;
$SQL_numViews = Convert::raw2sql($this->Views);
DB::query("UPDATE BlogEntry_Live SET Views = '$SQL_numViews' WHERE ID = $this->ID");
}
}
I gets called in the init():
function init() {
parent::init();
$this->incViews();
Requirements::themedCSS('blog');
}
I stole this idea from the FORUM-Module. Please tell me what you think about this feature.