我为我的页面创建GridField
has_many
与我DataObjects
的关系,但在添加数据并保存对象后,它会破坏CMS中的页面。我无法在搜索后找出原因或找到任何答案。这是错误和我的代码:
[用户错误]未捕获异常:对象 - > __ call():方法' fortemplate'在'文件'
上不存在
ProductPage.php
class ProductPage extends Page {
// Contact object's fields
public static $db = array(
'ProductPrice' => 'Text',
'ProductSubTitle' => 'Text',
'ProductModelNumber' => 'Text',
'ProductReleaseDate' => 'Date',
'AudioCode' =>'HTMLText',
// 'VideoCode' =>'HTMLText',
'ProductSold' =>'Boolean',
'NotAvailable' =>'Boolean',
'LimitedEdition' =>'Boolean',
'OneOff' =>'Boolean',
'Discontinued' =>'Boolean',
'DealerOnly' =>'Boolean',
'ComingSoon' =>'Boolean'
);
// One-to-one relationship with profile picture and contact list page
public static $has_one = array(
'ProductImage' => 'Image',
'ProductDownload' => 'File'
);
// One to many relationship with Contact object
public static $has_many = array(
'Videos' => 'Video',
'FirmwareDownloads' => 'FirmwareDownload'
);
private static $can_be_root = false;
private static $allowed_children = 'none';
private static $default_parent = 'Shop';
private static $description = 'Product for the Shop page';
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Audio', new TextAreaField('AudioCode','SoundClound Embed Code</br><a href="http://www.soundcloud.com" target="_blank">Visit SoundCloud</a>'));
// $fields->addFieldToTab('Root.Video', new TextAreaField('VideoCode','YouTube Embed Code</br><a href="http://www.youtube.com" target="_blank">Visit YouTube</a>'));
$fields->addFieldToTab('Root.Main', new TextField('ProductPrice','Price'),'Content');
$fields->addFieldToTab('Root.Main', new TextField('ProductSubTitle'),'Content');
$fields->addFieldToTab('Root.Main', new TextField('ProductModelNumber'),'Content');
$fields->addFieldToTab('Root.Main', $productDate = new DateField('ProductReleaseDate'),'Content');
$productDate->setConfig('showcalendar', true);
$productDate->setConfig('dateformat', 'd-MMMM-yyyy');
$fields->addFieldToTab('Root.Main', $manualuploadField = new UploadField('ProductDownload','Manual - PDF'),'Content');
$manualuploadField->setFolderName('manuals');
$fields->addFieldToTab('Root.Main', new CheckboxField('ProductSold','Sold Out'),'Content');
$fields->addFieldToTab('Root.Main', new CheckboxField('DealerOnly'),'Content');
$fields->addFieldToTab('Root.Main', new CheckboxField('NotAvailable'),'Content');
$fields->addFieldToTab('Root.Main', new CheckboxField('LimitedEdition'),'Content');
$fields->addFieldToTab('Root.Main', new CheckboxField('OneOff'),'Content');
$fields->addFieldToTab('Root.Main', new CheckboxField('Discontinued'),'Content');
$fields->addFieldToTab('Root.Main', new CheckboxField('ComingSoon'),'Content');
$fields->addFieldToTab('Root.Main', $uploadField = new UploadField('ProductImage','Featured Image'),'Title');
// $uploadField->setFolderName('.$parent->URLSegment'.$this->URLSegment);
$fields->renameField('Content','Product Description');
$fields->renameField('Title','Name');
$fields->renameField('NavigationLabel','Title');
$fields->fieldByName('Root.Main')->setTitle('Product Details');
$VideosGridField = new GridField(
'Videos',
'Videos',
$this->Videos(),
GridFieldConfig::create()
->addComponent(new GridFieldToolbarHeader())
->addComponent(new GridFieldAddNewButton('toolbar-header-right'))
->addComponent(new GridFieldSortableHeader())
->addComponent(new GridFieldDataColumns())
->addComponent(new GridFieldPaginator(50))
->addComponent(new GridFieldEditButton())
->addComponent(new GridFieldDeleteAction())
->addComponent(new GridFieldDetailForm())
->addComponent(new GridFieldSortableRows('SortOrder'))
);
$fields->addFieldToTab("Root.Videos", $VideosGridField);
$FirmwareDownloadsGridField = new GridField(
'FirmwareDownloads',
'Firmware Downloads',
$this->FirmwareDownloads(),
GridFieldConfig::create()
->addComponent(new GridFieldToolbarHeader())
->addComponent(new GridFieldAddNewButton('toolbar-header-right'))
->addComponent(new GridFieldSortableHeader())
->addComponent(new GridFieldDataColumns())
->addComponent(new GridFieldPaginator(50))
->addComponent(new GridFieldEditButton())
->addComponent(new GridFieldDeleteAction())
->addComponent(new GridFieldDetailForm())
->addComponent(new GridFieldSortableRows('SortOrder'))
);
$fields->addFieldToTab("Root.FirmwareDownload", $FirmwareDownloadsGridField);
return $fields;
}
public function getParentTitle() {
$parent = $this->Parent();
if ($parent->Exists()) {
return $parent->Title;
}
return '';
}
public function getGrandParentTitle() {
$parent = $this->Parent();
if ($parent->Exists()) {
$grandParent = $parent->Parent();
if ($grandParent->Exists()) {
return $grandParent->Title;
}
}
return '';
}
public function getGrandGrandParentPayPal() {
$parent = $this->Parent();
if ($parent->Exists()) {
$grandParent = $parent->Parent();
if ($grandParent->Exists()) {
$grandgrandParent = $grandParent->Parent();
if ($grandgrandParent->Exists()) {
return $grandgrandParent->PayPalEmail;
}
}
}
return '';
}
}
class ProductPage_Controller extends Page_Controller {
public function init() {
parent::init();
Requirements::css('shop/css/shop.css');
// Requirements::javascript('gallery/javascript/jquery-1.7.1.min.js');
// Magnific Popup core JS file -->
Requirements::javascript('gallery/javascript/jquery.magnific-popup.js');
Requirements::javascript('shop/javascript/organictabs.jquery.js');
// Magnific Popup core CSS file -->
Requirements::css('gallery/css/magnific-popup.css');
Requirements::css('gallery/css/magnific-popup-main.css');
Requirements::css('shop/css/shop.css');
}
}
class ProductPage_Images extends DataObject {
static $db = array (
'PageID' => 'Int',
'ImageID' => 'Int',
'Caption' => 'Text',
'SortOrder' => 'Int'
);
}
FirmwareDownload.php
class FirmwareDownload extends DataObject {
// Contact object's fields
public static $db = array(
'FirmwDownloadTitle' => 'Varchar(255)',
'SortOrder' => 'Int'
);
public static $default_sort = array('SortOrder');
// One-to-one relationship with Video picture and contact list page
public static $has_one = array(
'FirmwDownloadFile' => 'File',
'ProductPage' => 'ProductPage'
);
// Create Summary fields
public static $summary_fields = array(
'FirmwDownloadTitle' =>'Firmware Download Title',
'FirmwDownloadFile' =>'Firmware Download File'
);
// renames the summary columns
static $field_labels = array(
'FirmwDownloadTitle' =>'Firmware Download Title',
'FirmwDownloadFile' =>'Firmware Download File'
);
public function getCMSFields() {
$fields = FieldList::create(
TextField::create('FirmwDownloadTitle','Title'),
$uploader = UploadField::create('FirmwDownloadFile','EEPROM & Firmware File')
);
$uploader->setFolderName('firmware');
return $fields;
}
}
答案 0 :(得分:5)
问题在于这一行:
public static $summary_fields = array(
// ...
'FirmwDownloadFile' =>'Firmware Download File'
);
这会尝试在FirmwDownloadFile
中显示GridField
,但FirmwDownloadFile
是File
。 GridField
不知道如何显示File
。
我们可以做的是在File
中显示File.Name
变量,例如summary_fields
:
private static $summary_fields = array(
// ...
'FirmwDownloadFile.Name'
);
private static $field_labels = array(
// ...
'FirmwDownloadFile.Name' =>'Firmware Download File'
);
答案 1 :(得分:0)
这与更新表格SilverStripe有关。
早期版本:
private static $summary_fields = array(
'Field Name' => 'Model.Field'
);
当前版本:
private static $summary_fields = array(
'Model.Field' => 'Field Name'
);
您需要切换键/值对。