3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 747 Views |
-
trying to save custom data to image-table; almost there

28 January 2010 at 5:25am Last edited: 28 January 2010 5:25am
Hi,
I'm trying to save custom data to the image-table.
I thought it should be possible with $casting, but it appears not...With $this->Description the table-column has value NULL.
If I'm hardcoding some value instead (like 'MyTestValue'), the tablecolumn will get the value 'MyTestValue'.Since the hardcoding works, everything else seems right.
So it has something to do with the $casting and my calling of it.Can someone shed a light on it?
Code is below.Thanks a lot!
class ImagePage extends Page {
public static $has_one = array(
'testImage' => 'Image'
);
static $casting = array(
"Description" => "Varchar",
);public function getCMSFields() {
$fields = parent::getCMSFields();$testImage = new ImageField('testImage','Image');
$description = new TextField('Description','Description');
$fields->addFieldsToTab("Root.Content.Image", array(
$testImage,
$description,
));return $fields;
}public function onBeforeWrite() {
$myImage = DataObject::get_by_id('Image',$this->testImageID);
if($myImage){
$myImage->Description = $this->Description;
$myImage->write();
}
parent::onBeforeWrite();
}
...
| 747 Views | ||
|
Page:
1
|
Go to Top |

