php – Symfony2 – 更改捆绑名称后的Twig异常

我在Symfony 2.6.13中遇到了问题.
我创建了一个自定义类型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 }

我还在config.yml中添加了这个配置:

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(),);

这是getDaterangeType函数

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

更改这些文件名称有效.

非常感谢.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...