我有一个带有项目库的网站,网站上有专门用于项目类型的子页面。我想让内容管理员能够选择任何项目库项目以显示在他们选择的任何子页面上。一个子页面可以有多个项目库项,一个项目库项可以显示在一个或多个子页面上。
我设置了一个CheckboxSetField
显示Page.php
来自ProjectGalleryItem
DataObject 的所有项目名称的列表。我的复选框列表显示在所有子页面的单独选项卡中,但我无法保存任何选定的值 - 选中的复选框在保存时会自动取消选中。日志文件或控制台中未显示任何错误。
我想知道我之间的关系Page
是否ProjectGalleryItem
不正确?
这是代码ProjectGalleryItem
:
<?php
class ProjectGalleryItem extends DataObject
{
private static $db = array(
'ProjectName' => 'Varchar(250)',
'ProjectDescription' => 'Text',
);
private static $has_one = array(
'ProjectImage' => 'Image',
);
private static $belongs_many_many = array(
'Pages' => 'Page',
);
private static $summary_fields = array(
'ProjectName',
'ProjectDescription',
);
}
class ProjectGalleryItemAdmin extends ModelAdmin {
private static $managed_models = 'ProjectGalleryItem';
private static $url_segment = 'ProjectGalleryItems';
private static $menu_title = 'Project Gallery Items';
}
这是Page.php
文件的一半:
<?php
class Page extends SiteTree
{
private static $db = array(
'BannerH1' => 'HTMLText',
'BannerSubH1' => 'HTMLText',
'H1' => 'varchar(250)',
'PageTitle' => 'varchar(250)',
'BottomContent' => 'HTMLText',
'StylizedList' => 'HTMLText',
);
private static $has_one = array(
'BannerImg' => 'Image',
);
private static $has_many = array(
'RotatorImages' => 'RotatorImage',
);
private static $many_many = array(
'ProjectGalleryItems' => 'ProjectGalleryItem'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Main", new TextField("H1"), "Content");
$fields->addFieldToTab("Root.Main", new HTMLEditorField("BannerH1"), "Content");
$fields->addFieldToTab("Root.Main", new HTMLEditorField("BannerSubH1"), "Content");
$fields->addFieldToTab("Root.Main", new HTMLEditorField('BottomContent', "Bottom Content"));
$fields->addFieldToTab("Root.Main", new HTMLEditorField('StylizedList', "Stylized List"), "BottomContent");
$fields->addFieldToTab('Root.Main', new TextField('PageTitle', 'Page Title'), 'MetaDescription');
$fields->addFieldToTab("Root.Main", new UploadField('BannerImg', "Subpage Banner"), "Content");
$metadataTab = $fields->findOrMakeTab('Root.Main.Metadata');
$fields->removeByName('Metadata');
$fields->addFieldToTab('Root.Main', $metadataTab);
$gridFieldConfig = GridFieldConfig_RecordEditor::create();
$gridFieldConfig->addComponent(new GridFieldBulkUpload());
$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
// field from drawer class => label in UI
'ID' => 'ID',
'Title' => 'Title',
'Thumbnail' => 'Thumbnail',
'InternalURL.Link' => 'Internal URL',
));
$gridfield = new GridField(
"RotatorImages",
"Rotator Images",
$this->RotatorImages()->sort("SortOrder"),
$gridFieldConfig
);
$fields->addFieldToTab('Root.Rotator Images', $gridfield);
$projects = DataObject::get('ProjectGalleryItem');
if(!empty($projects))
{
$map = $projects->Map('ID', 'ProjectName');
$fields->addFieldToTab('Root.Projects',
CheckboxSetField::create(
$name = "Projects",
$title = "Select Projects",
$source = $map
));
}
return $fields;
}
}