2016-04-26 10 views
4

has_manyの関係をDataObjectsに設定していますが、データを追加してオブジェクトを保存すると、CMSのページが破損します。私は理由を理解することができず、検索後に何か答えを見つけることができません。SiverStripe 3:メソッド 'fortemplate'が 'File'に存在しません

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

このライン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

これはSilverStripe 3.0にあります。私たちは何ができるか

は、そのような私たちのsummary_fieldsFile.NameようFileの変数を表示するのですか?または3.1+?バージョン3.1から、静的変数は 'private'と宣言されるべきです。 – 3dgoo

答えて

5

問題されています:

public static $summary_fields = array(
    // ... 
    'FirmwDownloadFile' =>'Firmware Download File' 
); 
ここでエラーと私のコードです

これはGridFieldFirmwDownloadFileを表示しようとしますが、FirmwDownloadFileFileです。 GridFieldFileの表示方法がわかりません。

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

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

これは私の元の問題を解決しましたが、データオブジェクトを保存してページに戻ると、次のエラーが表示されます: "[User Warning]/home/dataabstract/public_htmlの1行目の出力のため、 /shop/code/ProductPage.php "とページレイアウトは完全に壊れています:www.pinkpoliceman.com/error.png、私はページとそのokを更新することができます..しかし、起こっている。 – pinkp

+1

ここで答えを見つけてください:http://stackoverflow.com/questions/34060991/strange-behavior-happening-in-silverstripe-backend、私は私のProductPage.phpの<?phpの前にスペースがありました – pinkp

関連する問題