I want to query some data in a month, so I wrote a form, add some fields, but I found that I can't select a month in Symfony2's date
, I have searched it in SF and found this:
show month number instead of month name on symfony2 formbuilder
I was very happy~~ Unfortunately, I found that can't work, the error information is:
The "format" option should contain the letters "y", "M" and "d".
Perhaps the cause is the version of Symfony2, which I used is Version 2.5.x.
Code:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$school_id = $this->user->getSchoolId();
$classes = $this->container->get('doctrine')->getRepository('ProjCoreBundle:TbBizClass')->findBySchoolId($school_id);
$classes_arr = array(0 => 'All Classes');
foreach ($classes as $class) {
$classes_arr[$class->getClassId()] = $class->getClassName();
}
$builder->setMethod('GET');
$builder->add('classId', 'choice', array(
'choices' => $classes_arr,
));
$builder->add('status', 'choice', array(
'choices' => array(
0 => 'All',
Checkroll::STATUS_ATTD_CASUAL => 'Casual',
Checkroll::STATUS_ATTD_SICK => 'Sick',
),
));
$builder->add('createdAt', 'date', array(
'format' => 'MMM-yyyy',
'years' => range(date('Y'), date('Y')+12),
'days' => array(1),
'empty_value' => array('year' => '----', 'month' => '----', 'day' => false)
));
}