Reputation: 111
I have two DataObjects on Silverstripe 4. First a Quiz whith a has_many-relationships with the questions for that Quiz.
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\CheckboxField;
class Quiz extends DataObject {
private static $db = [
"Name" => "Varchar(200)",
"bis" => "Date()",
"aktiv" => "Boolean",
"Mail" => "Boolean",
"MailText" => "Text"
];
private static $has_one = [
];
private static $has_many = [
"Fragen" => Quiz_Fragen::class
];
The code for the questions.
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
class Quiz_Fragen extends DataObject {
private static $db = [
"Frage" => "HTMLText",
"Art" => "Enum(array('auswählen','MC','Text','Check'))",
"OP1" => "Varchar(400)",
"OP2" => "Varchar(400)",
"OP3" => "Varchar(400)",
"OP4" => "Varchar(400)",
"Foul" => "Varchar(50)",
"Team" => "Enum(array('A','B'))",
"Punkte" => "Varchar(200)",
"Down" => "Enum(array('1','2','3','4','Try','FK'))",
"Pos" => "Varchar(25)",
"Distanz" => "Varchar(2)",
"Uhr" => "Enum(array('Snap','Ballfreigabe','Down ohne Zeit','keine','läuft'))",
"Sonstiges" => "Varchar(50)",
"Antwort" => "HTMLText",
"SortOrder" => "Int",
"Grund" => "HTMLText",
"Pkt" =>"Enum(array('1','2','3','4','5','6','7','8','9','10','11','12'))"
];
private static $has_one = [
"Quiz" => Quiz::class
];
private static $has_many = [
];
In Silverstripe 3 I chose a entry of the dataobject quiz an had a link on the top to see the questions related to the chosen quiz. I miss this link in Silverstripe 4. I'm sure I'm just missing a little thing. But I can't find a solution.
Upvotes: 0
Views: 37
Reputation: 111
It was the FieldList. On the dataobject Quiz I added the fields this way.
$fields = FieldList::create(
TextField::create('Name','Name des Quiz'),
DateField::create('bis','Quiz läuft bis'),
LiteralField::create("Text", "Vor der Aktivierung die Fragen eintragen. Sobald aktiviert wird bekommen die Benutzer eine E-Mail.<br /><br />"),
CheckboxField::create('aktiv', 'Quiz aktivieren')
);
When I use the old way of my SS 3 version. It works. So the problem is solved.
Upvotes: 1