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

图片转代码服务由CSDN问答提供 功能建议

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

这是我的代码

 &lt;?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'=&gt;'Varchar(255)',
'LinkText'=&gt;'varchar(50)'
); 
 private static $ has_one = array  (
'PageLink'=&gt;'SiteTree'
 
); 
公共函数getCMSFields(){
 $ fields = parent :: getCMSFields(); 
 $ fields-&gt; addFieldTo  Tab('Root.Main',TextareaField :: create('CTA','Call To Action Text'),'Content'); 
 $ fields-&gt; addFieldToTab('Root.Main',TreeDropdownField :: create(  'PageLinkID','此号召性用语链接到哪个页面?','SiteTree'),'内容'); 
 $ fields-&gt; addFieldToTab('Root.Main',TextField :: create('  PageLinkText','号召性用语链接文字(例如:“了解详情”)'),'内容'); 
 $ fields-&gt; removeByName('Content'); 
返回$ fields; 
} 
  } 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题