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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

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

Help me solve this, please


Go to End


2 Posts   2199 Views

Avatar
d_armin

Community Member, 8 Posts

3 April 2007 at 2:34am

Hello.
I have a ArticlePage.php and a ArticlePage.ss like in the tutorial described. Now, i want to count the number od views on this page. I have rebuild the database and i have "Views" in ArticlePage table.
This is my code, and it doesn't work.

class ArticlePage_Controller extends Page_Controller {

function CountViews(){

$i =DataObject::getField('Views');
$i++;
DataObject::setField("Views",$i);
DataObject::write();

}
}

I need a function that does not return anything, and just increment the Views in the ArticlePage table. What is wrong with this function? In the template i call this function with $CountViews.

Thank you

Avatar
xmedeko

Community Member, 94 Posts

28 May 2007 at 10:02am

instead DataObject::getField(...) try $this->getField(...) and similarly for the other functions