Hi
I am new to SilverStripe. I need to put a simple counter hit on the front page for my friend website. I have read the tutorial as how to create simple counter page at http://www.sslearn.info
I have created the PageCounter.php in /mysite/code/ as instructed.
[code taking from sslearn.info]
<?
class PageCounter extends DataObject{
static $db = array(
'Counter' => 'Int',
);
static $has_one = array(
'Page' => 'Page',
);
}
?>
[/code taking from sslearn.info]
adding counter function and code to output the content in /mysite/code/Page.php
insert in within the init() function of Page_Controller class
[code taking from sslearn.info]
$pagecounter = DataObject::get_one("PageCounter","PageID='$this->ID'");
if(!$pagecounter){
$pagecounter = new PageCounter();
$pagecounter->PageID=$this->ID;
}
$pagecounter->Counter = $pagecounter->Counter+1;
$pagecounter->write();
[/code taking from sslearn.info]
insert in within Page_Controller class
[code taking from sslearn.info]
public function pagecount(){
$pagecounter = DataObject::get_one("PageCounter","PageID='$this->ID'");
return $pagecounter->Counter;
}
[/code taking from sslearn.info]
I have rebuild the db and flush the page, everything is fine. In my Page.ss I tried to use the function above
<% control Counter %>
$Counter
<% end_control %>
There is nothing return. Hope that someone could help me here.
Many thanks in advance,
Phamo