2016-11-30 100 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

相关问题