添加更多 uploadFile 字段问题
Adding more uploadFile fields issue
我想在 CMS 中向我的滑块添加小图像。目前我这里的东西对我有用,我有一张大图片:
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
,据我所知这应该在数据库中添加新列,就像之前的图像一样,但我的问题是在数据库 table 中我只有第一张图片,没有添加第二张图片:
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;
}
}
所以请告诉我,因为我知道此列会自动添加,我应该清除缓存还是我做错了什么?帮我! :)
关系总是'YourRelationName' => 'Type'
的形式。所以你的 $has_one
关系定义应该是:
private static $has_one = array(
'HomePage' => 'HomePage',
'Image' => 'Image',
'SmallImage' => 'Image', // Use type 'Image', not 'SmallImage'
'Target' => 'Page',
);
我想在 CMS 中向我的滑块添加小图像。目前我这里的东西对我有用,我有一张大图片:
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
,据我所知这应该在数据库中添加新列,就像之前的图像一样,但我的问题是在数据库 table 中我只有第一张图片,没有添加第二张图片:
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;
}
}
所以请告诉我,因为我知道此列会自动添加,我应该清除缓存还是我做错了什么?帮我! :)
关系总是'YourRelationName' => 'Type'
的形式。所以你的 $has_one
关系定义应该是:
private static $has_one = array(
'HomePage' => 'HomePage',
'Image' => 'Image',
'SmallImage' => 'Image', // Use type 'Image', not 'SmallImage'
'Target' => 'Page',
);