SilverStripe 4 beta3 TreeDropdownField gives error: SourceObject must be a DataObject subclass

SilverStripe 4 beta3 TreeDropdownField gives error: SourceObject must be a DataObject subclass

我一定是遗漏了一些简单的东西...我在这里使用文档:http://api.silverstripe.org/en/master/class-SilverStripe.Forms.TreeDropdownField.html 我认为我这样做是正确的,但是出现错误:SourceObject 必须是 DataObject 子类

这是我的代码

<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
class HomePage extends Page {
    private static $db = array(
        'CTA'       => 'Varchar(255)',
        'LinkText'  => 'Varchar(50)'
    );
    private static $has_one = array(
        'PageLink'  => 'SiteTree'

    );
    public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Main', TextareaField::create('CTA', 'Call To Action Text'), 'Content');
        $fields->addFieldToTab('Root.Main', TreeDropdownField::create('PageLinkID', 'What page does this call-to-action link to?', 'SiteTree'), 'Content');
        $fields->addFieldToTab('Root.Main', TextField::create('PageLinkText', 'Call To Action Link Text (Example: "Learn more")'), 'Content');
        $fields->removeByName('Content');
        return $fields;
    }
}

您需要使用完全限定的 class 名称:

$fields->addFieldToTab(
    'Root.Main',
    TreeDropdownField::create(
        'PageLinkID',
        'What page does this call-to-action link to?',
        SiteTree::class
    ),
    'Content'
);

这也适用于您的模型关系:

private static $has_one = array(
    'PageLink'  => SiteTree::class,

);