我创建了一个自定义类型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','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; } }
因此,根据文档,我还将服务创建到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 }
twig: form: resources: - 'IronstatGeneralBundle:Form:Type:DaterangeType'
An exception has been thrown during the rendering of a template
(“Could not load type “date_range””) in
IronstatPacienteBundle:Page:edit.html.twig at line 27.
在我的表单中,我是这样添加的:
$builder->add('cau','collection',$this->getDaterangeType());
最后要知道的重要信息是它在对包的名称进行重构后停止工作(是的,我是个傻瓜,我知道……).
在重构之前它运行良好.在做了重构之后(我在整个项目中用ironstat改变了neostat),除了那之外一切正常.我删除了缓存并重新生成了bootstrap.PHP.cache,但它仍然无法正常工作.
我也确保很好地完成了重构.在整个项目中找到“Neostat”或“neostat”并没有给我带来结果.
缺什么?
非常感谢.
更新:这是我的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(),);
private function getDaterangeType() { return array( 'type' => 'date_range','allow_add' => true,'allow_delete' => true,'label_attr' => array('class' => 'control-label'),'empty_data' => null ); }
解决方法
问题是它缺少重命名文件(重构不是很好,大声笑).
显然,我需要重命名捆绑配置文件.
我注意到当我运行这个命令控制台时:
find ./ -name "Neostat*"
和文件列表是:
./Symfony/src/Ironstat/ReporteBundle/DependencyInjection/NeostatReporteExtension.PHP
./Symfony/src/Ironstat/usuarioBundle/DependencyInjection/NeostatusuarioExtension.PHP
./Symfony/src/Ironstat/ArchivoBundle/DependencyInjection/NeostatArchivoExtension.PHP
./Symfony/src/Ironstat/PacienteBundle/DependencyInjection/NeostatPacienteExtension.PHP
./Symfony/src/Ironstat/DiagnosticoBundle/DependencyInjection/NeostatDiagnosticoExtension.PHP
./Symfony/src/Ironstat/archivoBundle/DependencyInjection/NeostatarchivoExtension.PHP
./Symfony/src/Ironstat/envioBundle/DependencyInjection/NeostatenvioExtension.PHP
./Symfony/src/Ironstat/EnvioBundle/DependencyInjection/NeostatEnvioExtension.PHP
./Symfony/src/Ironstat/EntidadBundle/DependencyInjection/NeostatEntidadExtension.PHP
非常感谢.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。