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 /

DataObject non-DB properties losing state at template-time


Reply


350 Views

Avatar
Antsb

Community Member, 7 Posts

6 November 2013 at 11:03am

Edited: 06/11/2013 11:06am

This question is a cross-between data-model and templates, and the answer may be very obvious - as I'm very new to PHP:

I have a class that extends DataObject, and that I have added an additional private member property that I don't want serialised to the database, but that I do want to access during the template processing stage. For example:

class Deal extends DataObject {

static $db = array(
.......
);

private $cachedProperty;

public function setCachedProperty( $value) {
$this->cachedProperty = $value;
}

public function getCachedProperty() {
return $this->cachedProperty;
}
}

In my Page Controller I have a function that returns a list of Deal instances, but before it returns them, it sets this property above on each of them.

The problem is, when I call the function from my template, it always returns nothing for that property. I have put logging into the getCachedProperty() method and have verified that the template is invoking it, but it always seems to be empty.

Does anyone know why this is happening, and if there is something I can do to sort it out?