Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObject non-DB properties losing state at template-time

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

Page: 1
Go to End
Author Topic: 276 Views
  • Antsb
    Avatar
    Community Member
    7 Posts

    DataObject non-DB properties losing state at template-time Link to this post

    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?

    276 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.