Silverstripe Version: 4.13
Question: Database Date field is a string?
I’m currently trying to format a date with the →format function on my date object but I get an Call to a member function format() on string error
<?php
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
class EventDate extends DataObject {
private static $singular_name = "Veranstaltungsdatum";
private static $plural_name = "Veranstaltungsdaten";
private static $db = [
'city' => 'Text',
'from_date' => 'Date',
'to_date' => 'Date',
'is_online' => 'Boolean'
];
private static $has_one = [
"Page" => Page::class
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab(
"Root.Main",
TextField::create('city', 'Stadt')
);
$fields->addFieldToTab(
"Root.Main",
DateField::create('from_date', 'Von')
);
$fields->addFieldToTab(
"Root.Main",
DateField::create('to_date', 'Bis')
);
$fields->addFieldToTab(
"Root.Main",
CheckboxField::create('is_online', 'Online Veranstaltung')
);
return $fields;
}
// Custom title funktion für die formulare
public function getTitle() {
if($this->is_online) {
return $this->dbObject("from_date")->format("dd.MM.YYYY") . " bis " . $this->to_date->format("dd.MM.YYYY") . " | Online";
}
return $this->getField("from_date")->format("dd.MM.YYYY") . " bis " . $this->to_date->format("dd.MM.YYYY") . " | " . $this->city;
}
}
Is there something missing here or is this a but with 4.13? I know its out of support but the version is locked until development on this feature is complete