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.

Data Model Questions /

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

Data Model getters

Go to End

2 Posts   856 Views


Community Member, 1 Post

15 March 2014 at 5:22am

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.


Forum Moderator, 5523 Posts

15 March 2014 at 4:11pm

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;