Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Data Model getters

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

Page: 1
Go to End
Author Topic: 410 Views
  • Apocalypto
    Community Member
    1 Post

    Data Model getters Link to this post

    I'm looking to loop through a set of data objects, but I need to filter out those that the current time has not passed the 'publish date" field I created. Normally, I would do this when I run my DataObject::Get('ObjectName') method, and just use the '->Filter()' method to do so. But I was wondering if I can set it within the DataModel itself. Similar to how if you had a field "Title", you could implement a method:

    static $db = array (
    'Title' => 'Varchar(255)'

    public function getTitle() {
    //perform modifications
    return $this->Title;

    So within the same data model, it will only return itself, if it passes validation. Rather than just filtering every time I call it through a loop.

  • Willr
    Forum Moderator
    5511 Posts

    Re: Data Model getters Link to this post

    You can implement a getTitle but no, filter() won't pick this up for DataList's as it's SQL generated. It's useful for performing modifications between the database / display. Note to get the original value use something like

    public function getTitle() {
    $title = $this->dbObject('Title')->Value();


    return $title;

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.