21281 Posts in 5729 Topics by 2600 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 164 Views |
-
SS3 Defaults on a dataobject

4 December 2012 at 12:49am
Version Silvertsripe 3
Question: can you have defaults on a DataObject?
class EstateItem extends DataObject
{static $db = array(
'Active' => 'Boolean',);static $defaults = array(
'Active' => true
);}
this doesn't seem to work or 'Active' => 1
-
Re: SS3 Defaults on a dataobject

4 December 2012 at 1:45am
public function populateDefaults() {
parent::populateDefaults();
$this->Active = 1;
$this->URLSegment = 'new-EstateItem';
}function getCMSFields()
{
$fields = parent::getCMSFields();...
EstateItem::populateDefaults();}
EstateItem::populateDefaults(); seems to work ..but i only want that to happen for new records only.
-
Re: SS3 Defaults on a dataobject

4 December 2012 at 5:50am
For each of the fields you're adding in your getCMSFields() function, can you not do this?
$field->setValue('Some default value');
You can also check if it's a new record with:
if ($this->ID)
| 164 Views | ||
|
Page:
1
|
Go to Top |


