silverstripe / silverstripe-widgets

Widgets subsystem for Silverstripe CMS
http://silverstripe.org
BSD 3-Clause "New" or "Revised" License
38 stars 55 forks source link

Reading custom DB fields from controller. #131

Closed ElGabbu closed 8 years ago

ElGabbu commented 8 years ago

Hi all,

I setup a widget which has a db field:

private static $db = array(
        'FeaturedOnly' => 'Boolean'
    );

When trying to read that property from the controller's function using:

$this->widget->FeaturedOnly

I didn't get back a value ... the only way I found to manage to ready the correct value was:

$this->widget->dbObject('FeaturedOnly')->getValue()

Seems a bit cumbersome, I am not sure why my first approach didn't work but I noticed that in the record property of the widget the field was showing as lazy ...

[record:protected] => Array
        (
            [ClassName] => LatestNewsWidget
            [LastEdited] => 2016-07-01 11:40:15
            [Created] => 2016-07-01 11:19:19
            [Title] => Latest News
            [Sort] => 0
            [Enabled] => 1
            [Version] => 1
            [ParentID] => 1
            [ID] => 1
            [RecordClassName] => LatestNewsWidget
            [FeaturedOnly_Lazy] => LatestNewsWidget
        )

Thanks

dhensby commented 8 years ago

Do you experience this with a non-boolean value? If you add a string to the DB, does it work in your first example?

ElGabbu commented 8 years ago

I didn't try with other types I'm afraid however after a while it started working without any code changes :/ ... very weird, must be some sort of caching

dhensby commented 8 years ago

Ok. Thanks for the update