Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Count hits on links

Go to End



Community Member, 165 Posts

29 April 2009 at 10:39am

Edited: 29/04/2009 10:44am

I have a splash page that a client wants to count the hits on each of the three main links. All three links actually take the user to the same page but will give some analytics to the client. The usefulness of this aside I still need to figure out how to do it. Here is my SplashPage.php class:


class SplashPage extends Page {

public static $db = array(
'Contractor' => 'Int',
'Designer' => 'Int',
'Owner' => 'Int'

public static $has_one = array(

protected $ResetCounts = 0;

function getCMSFields() {
$fields = parent::getCMSFields();
// If this Boolean is set to true when the page is saved in the CMS then the database is reset for this page.
$fields->addFieldToTab("Root.Content.Main", new CheckboxField("ResetCounts", "Tick to reset click counters on save."), 'Content');
return $fields;

function onBeforeWrite() {
if ($this->ResetCounts > 0) {
$this->Contractor = 0;
$this->Designer = 0;
$this->Owner = 0;


class SplashPage_Controller extends Page_Controller {

function init() {

/* Note: I put these here instead of the template files so that my page types that inherit from Page.php and use the same
template can load thier own stylesheets and only need a Layout file. */
Requirements::javascript("site/javascript/SplashPage.js"); // MainNav.js is used for dropdown/flyout menus in IE 6.

if (isset($this->URLParams['Action'])) {
if ($this->URLParams['Action'] == "Contractor"){$this->Contractor += 1;}
else if ($this->URLParams['Action'] == "Designer"){$this->Designer += 1;}
else if ($this->URLParams['Action'] == "HomeOwner"){$this->HomeOwner += 1;}



The reset checkbox in the CMS works just fine to set the values back to zero in the database however the bit of code that checks the URLParams['Action'] vales does not seem to work at least not for incrementing the database values.