dse323222 2017-09-26 15:26
浏览 55
已采纳

SilverStripe 4 beta3 TreeDropdownField给出错误:SourceObject必须是DataObject的子类

I must be missing something simple...I'm using the documentation here: http://api.silverstripe.org/en/master/class-SilverStripe.Forms.TreeDropdownField.html and I think I'm doing this correctly, but getting the error : SourceObject must be a DataObject subclass

This is my code

<?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;
    }
}
  • 写回答

1条回答 默认 最新

  • douzhaishan5462 2017-09-26 20:15
    关注

    You need to use a fully qualified class name:

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

    This also goes for your model relations:

    private static $has_one = array(
        'PageLink'  => SiteTree::class,
    
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面