2016-11-30 56 views
0

我想將小圖像添加到CMS中的滑塊。目前,對我來說我到這裏是什麼在起作用,我有一個很大的圖片:添加更多uploadFile字段問題

class Banner extends SortableObject { 

    private static $db = array(
    ); 

    private static $has_one = array(
     'HomePage' => 'HomePage', 
     'Image' => 'Image', 
     'Target' => 'Page', 
    ); 

    private static $summary_fields = array(
     'ID', 
     'Target.MenuTitle', 
    ); 

    public function getCMSFields() { 
     $fields = new FieldList(); 

     $img = new UploadField('Image'); 
     $img->setFolderName('hpbanners'); 
     $img->getValidator()->setAllowedExtensions(array('jpg','gif','png')); 
     $fields->push($img); 

     $drop = new TreeDropdownField('TargetID','Choose page','SiteTree'); 
     $fields->push($drop); 

     return $fields; 
    } 
} 

現在我想添加一個字段。我加$smallImage,據我所知這應該之前在數據庫中添加新列,就像圖片,但我的問題是,在數據庫表我只有第一形象,二是不添加:

class Banner extends SortableObject { 

    private static $db = array(
    ); 

    private static $has_one = array(
     'HomePage' => 'HomePage', 
     'Image' => 'Image', 
     'SmallImage' => 'SmallImage', 
     'Target' => 'Page', 
    ); 

    private static $summary_fields = array(
     'ID', 
     'Target.MenuTitle', 
    ); 

    public function getCMSFields() { 
     $fields = new FieldList(); 

     $img = new UploadField('Image'); 

     $img->setFolderName('hpbanners'); 
     $img->getValidator()->setAllowedExtensions(array('jpg','gif','png')); 
     $fields->push($img); 

     $smallImage = new UploadField('SmallImage'); 
     $smallImage->getValidator()->setAllowedExtensions(array('jpg','gif','png')); 
     $fields->push($smallImage); 

     $drop = new TreeDropdownField('TargetID','Choose page','SiteTree'); 
     $fields->push($drop); 

     return $fields; 
    } 
} 

所以,請告訴我,因爲我知道這個列會自動添加,應該清除緩存還是我做錯了什麼?幫我! :)

回答

1

關係總是形式爲'YourRelationName' => 'Type'。所以你的$has_one關係的定義應該是:

private static $has_one = array(
    'HomePage' => 'HomePage', 
    'Image' => 'Image', 
    'SmallImage' => 'Image', // Use type 'Image', not 'SmallImage' 
    'Target' => 'Page', 
); 
+0

好吧,其他的事情是正確的?那我應該清理現金嗎?沖洗所有或其他? – user2962010

+0

'dev/build'應該足夠了。 – bummzack

相關問題