2016-04-26 5 views
4

Ich erstelle eine GridField für meine Seite mit einer has_many Beziehung zu meiner DataObjects aber nach dem Hinzufügen von Daten und Speichern des Objekts bricht es die Seite im CMS. Ich kann nicht herausfinden warum oder irgendwelche Antworten nach dem Suchen finden. Hier ist der Fehler und mein Code:SiverStripe 3: Die Methode 'Fortemplate' existiert nicht in 'Datei'

[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

Ist das in Silvers 3.0? Oder 3.1+? Ab Version 3.1 sollten statische Variablen als 'privat' deklariert werden. – 3dgoo

Antwort

5

Das Problem ist diese Zeile:

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

Dies wird versuchen, die FirmwDownloadFile in der GridField anzuzeigen, aber FirmwDownloadFile ist eine File. GridField kann nicht File anzeigen.

Was wir tun können, ist eine Variable File angezeigt wie die File.Name in unserem summary_fields:

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

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

Dies löste mein ursprüngliches Problem, aber nach dem Speichern des Datenobjekts und dem Zurückkehren zur Seite erhalte ich folgende Fehlermeldung: "[Benutzerwarnung] Der Antworttyp konnte wegen der Ausgabe in Zeile 1 von/home/dataabstract/public_html nicht auf 404 gesetzt werden /shop/code/ProductPage.php "und das Seitenlayout ist total kaputt wie folgt: www.pinkpoliceman.com/error.png, ich kann die Seite aktualisieren und es ist ok. Aber passiert weiter. – pinkp

+1

Scratch, dass die Antwort hier: http://stackoverflow.com/questions/34060991/strange-behavior-happening-in-silverstripe-backend, ich hatte ein Leerzeichen vor der pinkp

Verwandte Themen