estoy tratando de mostrar unicamente los años en un combo dentro de un formulario
...
private $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$dql = "SELECT DISTINCT(f.fecha) as fecha FROM AdminBundle:Documento f ORDER BY f.fecha desc";
$results = $this->em->createQuery($dql)->getArrayResult();
$choices = array();
foreach ($results as $result) {
$choices[$result['fecha']->format('Y')] = $result['fecha']->format('Y');
}
->add('fecha', 'choice', array(
'label' => 'Años',
'attr' => array('style' => 'width:100px'),
'empty_value' => '--Todos--',
'required' => false,
'choices' => $choices
))
....
Si quito ->format('Y') y lo dejo así:
$choices[$result['fecha']] = $result['fecha']; ( me muestra las fechas (2015-11-03))
pero como necesito mostrar solo los años al agregar el formato ->format('Y') así:
$choices[$result['fecha']->format('Y')] = $result['fecha']->format('Y');
symfony2 me genera el siguiente error:
Error: Call to a member function format() on string
pueden ayudarme a corregir ese error por favor