Has_many在ModelAdmin上

时间:2018-03-17 19:38:31

标签: php silverstripe silverstripe-4 modeladmin

我在Silverstripe 4上有两个DataObjects。 首先是一个测验,与测验的问题有很多关系。

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
    ];

问题的代码。

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 = [

    ];

在Silverstripe 3中,我选择了一个数据对象测验的条目,并在顶部有一个链接,以查看与所选测验相关的问题。我想念Silverstripe 4中的这个链接。我确定我只是错过了一件小事。但我找不到解决方案。

1 个答案:

答案 0 :(得分:1)

这是FieldList。 在数据对象测验中,我以这种方式添加了字段。

$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')
        );

当我使用旧版SS 3版本时。有用。所以问题就解决了。