简体   繁体   中英

How to set minimum year value in Sonata Admin Bundle date form field

I'm using Sonata Admin Bundle with Symfony2. I have a datetime field. This is my piece of code. Pretty simple.

->add('passportIssueDate', 'date')

But in the form I can select Year value only from 2008 to 2018. Is there a way to set different range? Thanks in advance.

You would use something like this:

$builder->add('dob', 'birthday', array('years' => range(1980, date('Y')), 'format' => 'dd-MMMM-yyyy'));

This means the Date Field (regardless of if it's DateTime, Date, or Birthday) will give you a range from 1980 in this case to the current year. To get a range including years in the future, you would use something like this:

$builder->add('startDate', 'date', array('years' => range(2012, 2020), 'format' => 'dd-MMMM-yyyy'));

This instance gives you a range from 2012 to 2010.

Furthermore, the 'format' => 'dd-MMMM-yyyy' will format your date selection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM