Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Help me solve this, please

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

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

Page: 1
Go to End
Author Topic: 1611 Views
  • d_armin
    Avatar
    Community Member
    8 Posts

    Help me solve this, please Link to this post

    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

  • xmedeko
    Avatar
    Community Member
    94 Posts

    Re: Help me solve this, please Link to this post

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

    1611 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.