dongyou1926 2016-11-30 18:14
浏览 42
已采纳

添加更多uploadFile字段问题

I want to add small image to my slider in CMS. Currently what I have down here works for me, I have one big Image:

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;
    }
}

Now I want to add another field. I added $smallImage, as I understand this should add new column in DB, just like Image before, but my problem is that in DB table I have only first image, second is not added:

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;
    }
}

So please tell me, as I know this column will be automatically added, should I clear cache or what am I doing wrong? Help me! :)

  • 写回答

1条回答 默认 最新

  • dongzeao5047 2016-11-30 19:44
    关注

    Relations are always in form of 'YourRelationName' => 'Type'. So your $has_one relation definition should read:

    private static $has_one = array(
        'HomePage' => 'HomePage',
        'Image' => 'Image',
        'SmallImage' => 'Image', // Use type 'Image', not 'SmallImage'
        'Target' => 'Page',
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件