Php 背景图像上传字段不';不显示在CMS中
在SilverStripe CMS网站上,我有一个自定义的页脚附加代码,我想扩展它,以便在CMS中上传背景图像。代码看起来不错,但添加的字段在CMS中找不到 这是我的代码:Php 背景图像上传字段不';不显示在CMS中,php,silverstripe,Php,Silverstripe,在SilverStripe CMS网站上,我有一个自定义的页脚附加代码,我想扩展它,以便在CMS中上传背景图像。代码看起来不错,但添加的字段在CMS中找不到 这是我的代码: class CustomFooter extends DataExtension { static $db = array( 'FooterContent' => 'HTMLText' ); public static $has_one = array( 'L
class CustomFooter extends DataExtension {
static $db = array(
'FooterContent' => 'HTMLText'
);
public static $has_one = array(
'Logo' => 'Image',
'BGImage' => 'Background Image'
);
public function getCMSFields() {
$this->extend('updateCMSFields', $fields);
return $fields;
}
public function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab('Root.Footer', new HTMLEditorField('FooterContent', 'Footer Content'));
$fields->addFieldToTab('Root.Main', new UploadField('Logo', 'Company Logo'));
$fields->addFieldToTab('Root.Main', new UploadField('BGImage', 'Background image'));
}
}
奇怪的是,这两个图像上传字段都没有显示内容选项卡显示的位置,功能也没有达到预期
为什么上载字段不显示?您的
public static $has_one = array(
"Logo"=>"Image",
"BGImage"=>"Background Image"
);
看起来很奇怪。$has\u one
数组将关系名称作为键,将关系的类名作为值,我怀疑名称中是否允许使用带空格的类名。所以我想试试这样的东西
public static $has_one = array(
"Logo"=>"Image",
"BGImage"=>"Image"
);
然后运行一个dev/build?flush
,并在数据库中检查您的表是否有一个LogoID
列和一个BGImageID
列,以表示该表有一个关系
字段生成看起来不错,应该可以正常工作。最大的问题是我的UploadField中的根集。。。。。代码起作用了,我所做的是,我将UploadField指向那个人,而不是我的页脚标签$fields->addFieldToTab('Root.Main',new UploadField('BGImage','Background image');我想说:$fields->addFieldToTab('Root.Footer',newuploadfield('BGImage','backgroundimage');