gpt4 book ai didi

php - 银条 3 : the method 'fortemplate' does not exist on 'File'

转载 作者:可可西里 更新时间:2023-10-31 22:52:16 26 4
gpt4 key购买 nike

我正在为我的页面创建一个 GridField,它与我的 DataObjects 有一个 has_many 关系,但是在添加数据并保存对象后它会中断CMS 中的页面。搜索后我无法弄清楚原因或找不到任何答案。这是错误和我的代码:

[User Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'File'

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

固件下载.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;
}
}

最佳答案

问题是这一行:

public static $summary_fields = array(
// ...
'FirmwDownloadFile' =>'Firmware Download File'
);

这将尝试在 GridField 中显示 FirmwDownloadFile,但 FirmwDownloadFile 是一个 FileGridField 不知道如何显示 File

我们可以做的是在 summary_fields 中显示一个 File 变量,例如 File.Name:

private static $summary_fields = array(
// ...
'FirmwDownloadFile.Name'
);

private static $field_labels = array(
// ...
'FirmwDownloadFile.Name' =>'Firmware Download File'
);

关于php - 银条 3 : the method 'fortemplate' does not exist on 'File' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36877755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com