Php SiverStripe 3:方法';fortemplate&x27;不存在于';文件';

Php SiverStripe 3:方法';fortemplate&x27;不存在于';文件';,php,silverstripe,Php,Silverstripe,我正在为我的页面创建一个GridField,其中与我的DataObjects有很多关系,但在添加数据并保存对象后,它会在CMS中中断页面。我找不出原因,也找不到任何答案。以下是错误和我的代码: [用户错误]未捕获异常:对象->\u调用():方法“fortemplate”在“File”上不存在 ProductPage.php class ProductPage extends Page { // Contact object's fields public static $db

我正在为我的页面创建一个
GridField
,其中
与我的
DataObjects
有很多关系,但在添加数据并保存对象后,它会在CMS中中断页面。我找不出原因,也找不到任何答案。以下是错误和我的代码:

[用户错误]未捕获异常:对象->\u调用():方法“fortemplate”在“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'
    );
}
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'
);
这将尝试在
网格字段中显示
FirmwDownloadFile
,但
FirmwDownloadFile
文件<代码>网格字段
不知道如何显示
文件

我们可以做的是在我们的
摘要\u字段中显示
文件
的变量,例如
File.Name

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

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

这与更新表单SilverStripe有关

早期版本:

private static $summary_fields = array(
    'Field Name' => 'Model.Field'
);
当前版本:

private static $summary_fields = array(
    'Model.Field' => 'Field Name'
);

您需要切换键/值对。

这是否在SilverStripe 3.0中?还是3.1+?从3.1版开始,静态变量应该声明为
private
。这解决了我最初的问题,但现在在保存数据对象并返回页面后,我得到了以下错误:“[用户警告]无法将响应类型设置为404,因为/home/dataabstract/public\u html/shop/code/ProductPage.php的第1行上有输出。”页面布局完全是这样:www.pinkpoliceman.com/error.png,我可以刷新页面,然后就可以了。。但是一直在发生。在这里,答案是:,我在