Search the Community
Showing results for tags 'locked'.
-
I want to make a little module that tracks pageviews. This is my first module. I'm starting with a copy of helloworld.module. I already created the template pageviews and pageview manually, but I'll add their creation into the module later. Here's what I have: public function viewTracker($event) { $page = $event->object; // don't add this to the admin pages if($page->template == 'admin') return; if($page->template == 'vessel') { $r = new Page(); $r->template = 'pageview'; $r->parent = wire('pages')->get('/viewtracker/'); $r->user = $user->name; $r->vessel_id = $page->id; $r->name = $user->id . $page->id . date('YmdHisu'); //$r->status = $r->status | Page::statusLocked; $r->save(); } // add a "Hello World" paragraph right before the closing body tag $event->return = str_replace("</body>", "<p>Hello $user World!</p></body>", $event->return); } but the $user variable isn't coming through. How can I access the logged in $user? Edit: Got it. Replaced the $user with $this->user..... public function viewTracker($event) { $page = $event->object; // don't add this to the admin pages if($page->template == 'admin') return; if($page->template == 'vessel') { $r = new Page(); $r->template = 'pageview'; $r->parent = wire('pages')->get('/viewtracker/'); $r->user = $this->user; $r->vessel_id = $page; $r->name = $this->user . $page . date('YmdHisu'); $r->status = $r->status | Page::statusHidden; $r->save(); } }