具有范围日期时间(窗体)的符号问题



我不明白我的问题。 如果你能给我一个想法。 我有一个日期时间字段谁工作,但 我的领域年份有一个奇怪的范围(2015-2025(。 我想要一个更大的范围(例如:1960-2040(。

class BookType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('author')
->add('publicationDate')
->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',
])
]
])
;
}

正如你在这里看到的 DateType::Class Rerefence。该字段将具有用于配置选择框行为方式的选项。你可以简单地使用PHP的range((函数在你的代码中映射出你的年份,比如: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',
])
]
])
;
}

最新更新