I have a problem in Symfony 2.6.13. I created a special type GeneralBundle / Form / Type / DateRangeType.php:
<?php
namespace Ironstat\GeneralBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class DateRangeType extends AbstractType
{
const NAME = 'date_range';
private $manager;
public function __construct($manager) {
$this->manager = $manager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('dateFrom', 'date', array(
'widget' => 'single_text',
'format' => 'dd/MM/yyyy',
'attr' => array('class' => 'datepicker input-small'),
'label_attr' => array('class' => 'control-label label-sm'),
'label' => 'Fecha desde',
'empty_value' => false,
))
->add('dateTo', 'date', array(
'widget' => 'single_text',
'format' => 'dd/MM/yyyy',
'attr' => array('class' => 'datepicker input-small'),
'label_attr' => array('class' => 'control-label label-sm'),
'label' => 'Fecha hasta',
'empty_value' => false
));
$transformer = new DateRangeTransform($this->manager);
$builder->addModelTransformer($transformer);
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Ironstat\GeneralBundle\Entity\DateRange',
));
}
public function getName() {
return self::NAME;
}
}
So, according to the docs, I also create a service in GeneralBundle / Resources / config / services.yml:
services:
ironstat.type.date_range:
class: Ironstat\GeneralBundle\Form\Type\DateRangeType
arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: form.type, alias: date_range }
I also add this configuration to config.yml:
twig:
form:
resources:
- 'IronstatGeneralBundle:Form:Type:DateRangeType'
But, when I try to add it to my form, I got this error:
During template rendering, an exception was thrown ("Unable to load type 'date_range') in IronstatPacienteBundle: Page: edit.html.twig on line 27.
In my form, I add it like this:
$builder->add('cau' , 'collection' , $this->getDateRangeType());
, , , (, , ...).
. ( ), , . bootstrap.php.cache, .
, . "" "" .
?
.
UPDATE: appKernel.php:
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Ironstat\PacienteBundle\IronstatPacienteBundle(),
new Ironstat\DiagnosticoBundle\IronstatDiagnosticoBundle(),
new Ironstat\EntidadBundle\IronstatEntidadBundle(),
new Ironstat\usuarioBundle\IronstatusuarioBundle(),
new Ironstat\GeneralBundle\IronstatGeneralBundle(),
new Siphoc\PdfBundle\SiphocPdfBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Ironstat\EnvioBundle\IronstatEnvioBundle(),
new Ironstat\ArchivoBundle\IronstatArchivoBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new Ironstat\ReporteBundle\IronstatReporteBundle(),
new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
);
getDateRangeType:
private function getDateRangeType() {
return array(
'type' => 'date_range',
'allow_add' => true,
'allow_delete' => true,
'attr' => array('class' => 'datepicker input-small'),
'label_attr' => array('class' => 'control-label'),
'empty_data' => null
);
}