加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:28:02 所属栏目:PHP教程 来源:网络整理
导读:我在Symfony 2.6.13中遇到了问题. 我创建了一个自定义类型GeneralBundle / Form / Type / DateRangeType.php: ?phpnamespace IronstatGeneralBundleFormType;use SymfonyComponentFormAbstractType;use SymfonyComponentFormFormBuilderInterface;
我在Symfony 2.6.13中遇到了问题.
我创建了一个自定义类型GeneralBundle / Form / Type / DateRangeType.php:

<?php

namespace IronstatGeneralBundleFormType;

use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolverInterface;

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' => 'IronstatGeneralBundleEntityDateRange',));
    }

    public function getName() {
        return self::NAME;
    }
}

因此,根据文档,我还将服务创建到GeneralBundle / Resources / config / services.yml中:

services:
    ironstat.type.date_range:
        class: IronstatGeneralBundleFormTypeDateRangeType
        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 SymfonyBundleFrameworkBundleFrameworkBundle(),new SymfonyBundleSecurityBundleSecurityBundle(),new SymfonyBundleTwigBundleTwigBundle(),new SymfonyBundleMonologBundleMonologBundle(),new SymfonyBundleSwiftmailerBundleSwiftmailerBundle(),new SymfonyBundleAsseticBundleAsseticBundle(),new DoctrineBundleDoctrineBundleDoctrineBundle(),new SensioBundleFrameworkExtraBundleSensioFrameworkExtraBundle(),new IronstatPacienteBundleIronstatPacienteBundle(),new IronstatDiagnosticoBundleIronstatDiagnosticoBundle(),new IronstatEntidadBundleIronstatEntidadBundle(),new IronstatusuarioBundleIronstatusuarioBundle(),new IronstatGeneralBundleIronstatGeneralBundle(),new SiphocPdfBundleSiphocPdfBundle(),new FOSUserBundleFOSUserBundle(),new IronstatEnvioBundleIronstatEnvioBundle(),new IronstatArchivoBundleIronstatArchivoBundle(),new KnpBundlePaginatorBundleKnpPaginatorBundle(),new IronstatReporteBundleIronstatReporteBundle(),new KnpBundleSnappyBundleKnpSnappyBundle(),);

这是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

更改这些文件的名称有效.

非常感谢.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读