like this
http://doc.silverstripe.com/doku.php?id=datamodel#overloading
“Getters†and “Setters†are functions that help us save fields to our data objects
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
like this
http://doc.silverstripe.com/doku.php?id=datamodel#overloading
“Getters†and “Setters†are functions that help us save fields to our data objects
Yes. They support everything that you can have from a normal page.
but seems it does not work
<?php
class TestWidget extends Widget {
static $db = array(
"Myvalue" => "Text"
);
static $title = "Test widget";
static $cmsTitle = "Test widget";
static $description = "Test Test Test Test";
function getCMSFields() {
return new FieldSet(
new TextField("Myvalue" , "Myvalue" )
);
}
function getMyvalue(){
if($this->Myvalue){
return $this->Myvalue;
}else{
return "default value";
}
}
function setMyvalue($value){
$this->setField("Myvalue" , "hoho".$value);
}
}
?>
This is because when you're calling $this->Myvalue in getMyvalue, SilverStripe then goes and calls getMyvalue, which causes an infinite loop. You need to use $this->getField('Myvalue')
i changed as following
function getMyvalue(){
//return $this->getField("Myvalue");
return "myvalue";
}
it does not work even i return a string
and the
function setMyvalue($val){
$this->setField("Myvalue" , "prefix".$val."suffix");
}
it can not work too.
:(((