1 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個贊
正如你在這里看到的 日期類型::類折射。該字段將包含用于配置選擇框行為方式的選項(xiàng)。你可以簡單地使用php的range()函數(shù)來繪制你的代碼中的年份,比如:range(1960,2040)
$builder->add('field', DateType::Class , [
'years' => range(date('Y')-50, date('Y')+50) // Lists 50 Years Before and After
]);
在代碼中,只需使用 :
class BookType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('author')
->add('publicationDate', DateType::Class , [
'years' => range(1960, date('Y')+20) // Change As eper your requirements
])
->add('format')
->add('language')
->add('user')
->add('excelFile', FileType::class,[
'label' => 'Fichier excel (xls/xlsx file)',
'mapped' => false,
'required' => false,
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
],
'mimeTypesMessage' => 'Please upload a valid xls/xlsx document',
])
]
])
;
}
- 1 回答
- 0 關(guān)注
- 101 瀏覽
添加回答
舉報(bào)