Php Symfony2-更改捆绑包名称后出现细枝异常
我在Symfony 2.6.13中遇到问题。 我创建了一个自定义类型GeneralBundle/Form/type/DateRangeType.php:Php Symfony2-更改捆绑包名称后出现细枝异常,php,symfony,twig,Php,Symfony,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\Option
<?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;
}
}
我还将以下配置添加到config.yml中:
twig:
form:
resources:
- 'IronstatGeneralBundle:Form:Type:DateRangeType'
但是,当我尝试将其添加到表单中时,出现以下错误:
在呈现模板期间引发了异常
(“无法在中加载类型“日期范围”)
IronstatPacienteBundle:Page:edit.html.twig,第27行
在我的表格中,我这样添加它:
$builder->add('cau' , 'collection' , $this->getDateRangeType());
最后一个重要的信息是,它在对bundle的名称进行重构后停止工作(是的,我是个傻瓜,我知道…)。
在重构之前,它工作得很好。在进行重构(我在整个项目中用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,
'attr' => array('class' => 'datepicker input-small'),
'label_attr' => array('class' => 'control-label'),
'empty_data' => null
);
}
我找到了解决办法:
问题是缺少重命名文件(重构做得不太好,哈哈)。
显然,我需要重命名包配置文件。
我注意到当我运行这个命令控制台时:
find ./ -name "Neostat*"
文件清单如下:
./Symfony/src/Ironstat/ReporteBundle/DependencyInjection/neostatreportextension.php
./Symfony/src/Ironstat/usuaribundle/DependencyInjection/neostatuarioextension.php
./Symfony/src/Ironstat/ArchivoBundle/DependencyInjection/NeostatArchivoExtension.php
./Symfony/src/Ironstat/PacienteBundle/DependencyInjection/neostatpacientextension.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
更改这些文件的名称是有效的
非常感谢。您调整自动装载机了吗?是的,我重新生成了它。这是一个很好的尝试,但仍然失败…显示此捆绑包的AppKernel您的
$this->getDateRangeType()
函数是什么样子的?是的,我很抱歉。我更新了我的帖子,在AppKernel.php中添加了registerBundles函数和getDateRangeType函数。
find ./ -name "Neostat*"