Symfony表单抛出错误:无法实例化特征

时间:2015-05-20 12:45:01

标签: php forms symfony traits

我在编辑表单上出现错误,只在生产环境中发生。我在PHP 5.4.10 / Apache 2.4.4服务器上使用Symfony 2.6.3。

我无法在开发环境中重新制作该错误。

这是跟踪:

php.EMERGENCY: Fatal Error: Cannot instantiate trait (null) {"type":1,"file":"/app/list/home/appadm01/Corsaire/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php","line":184,"level":22527,"stack":[]} []
request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Error: Cannot instantiate trait (null)" at /app/list/home/appadm01/Corsaire/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 184 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 0): Error: Cannot instantiate trait (null) at /app/list/home/appadm01/Corsaire/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php:184)"} []

所以我在第184行查看了Form.php文件:

        $this->children = new OrderedHashMap();

,OrderedHashMap的构造函数是:

public function __construct(array $elements = array())
{
    $this->elements = $elements;
    $this->orderedKeys = array_keys($elements);
}

我不明白为什么会发生这种错误......没有"使用"在课堂上。 所以这是表单类型:

namespace Silca\CorsaireRefCotBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Silca\CorsaireRefCotBundle\Entity\Application;
use Doctrine\ORM\EntityRepository;

class ApplicationType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('codeAppli', null, array(
                'label' => 'Code applicatif'
            ))
            ->add('nomAppli', null, array(
                'label' => 'Nom de l\'application'
            ))
            ->add('description', null, array(
                'label' => 'Description'
            ))
            ->add('dICP', null, array(
                'label' => 'DICP'
            ))
            ->add('nVCP', null, array(
                'label' => 'NVCP'
            ))
            ->add('compServeur',null, array(
                'label' => 'Composant serveur'
            ))
            ->add('compRelation', null, array(
                'label' => 'Composant relation'
            ))
            ->add('compBDD', null, array(
                'label' => 'Composant BDD'
            ))
            ->add('txDispo', 'percent', array(
                'type' => 'integer',
                'label' => 'Taux de disponibilité',
                'required'  => false
            ))
            ->add('exploitabilite', 'choice', array(
                'choices' => Application::getTypesExploit(),
                'label' => 'Exploitabilité',
                'expanded' => true,
                'required'  => false,
                'empty_value' => 'N/A'
                ))
            ->add('dIMA', null, array(
                'label' => 'DIMA'
            ))
            ->add('pDMA', null, array(
                'label' => 'PDMA'
            ))
            ->add('critique', 'choice', array(
                'label' => 'Application critique ?',
                'choices' => Application::getTypesCritique(),
                'expanded' => true
            ))
            ->add('dateOuverture', 'date', array(
                'widget' => 'text',
                'format' => 'ddMMyyyy',
                'label' => 'Date d\'ouverture (Jour/Mois/Année)',
                'invalid_message' => 'La date n\'est pas correcte'
            ))
            ->add('dateFermeture', 'date', array(
                'widget' => 'text',
                'format' => 'ddMMyyyy',
                'required' => false,
                'empty_data' => null,
                'label' => 'Date de fermeture (Jour/Mois/Année)',
                'invalid_message' => 'La date n\'est pas correcte'
            ))
            ->add('domaine', null, array(
                'label' => 'Domaine'
            ))
            ->add('gtr', null, array(
                'label' => 'GTR'
            ))
            ->add('plagedeservice', null, array(
                'label' => 'Plage de service'
            ))
            ->add('client', null,array(
                'label' => 'Client'
            ))
            ->add('iemNominal', "entity", array(
                'class' => 'Silca\CorsaireUtilisateurBundle\Entity\Utilisateur',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('u')->join('u.equipe', 'e')->where('e INSTANCE OF Silca\CorsaireRefCotBundle\Entity\Exploit')->orderBy('u.nom', 'ASC');
                    },
                'group_by' => 'equipe',
                'empty_value' =>"",
                'label' => 'IEM Nominal',
                'required'  => false
            ))
            ->add('moe', null, array(
                'attr' => array("onchange"=>'enableMoe()'),
                'label' => 'MOE'
            ))
            ->add('exploit',null, array(
                'attr' => array("onchange"=>'enableExploit()'),
                'label' => 'Equipe d\'exploitation'
            ))
            ->add('iems', "entity", array(
                'class' => 'Silca\CorsaireUtilisateurBundle\Entity\Utilisateur',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('u')->join('u.equipe', 'e')->where('e INSTANCE OF Silca\CorsaireRefCotBundle\Entity\Exploit')->orderBy('u.nom', 'ASC');
                    },
                'group_by' => 'equipe',
                'empty_value' =>"",
                'multiple' => true,
                'label' => 'Ingenieur d\'exploitation',
                'required'  => false
            ))
            ->add('cdp', "entity", array(
                'class' => 'Silca\CorsaireUtilisateurBundle\Entity\Utilisateur',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('u')->join('u.equipe', 'e')->where('e INSTANCE OF Silca\CorsaireRefCotBundle\Entity\Moe')->orderBy('u.nom', 'ASC');
                    },
                'group_by' => 'equipe',
                'empty_value' =>"",
                'label' => 'Chargé de projet',
                'required'  => false
            ))
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Silca\CorsaireRefCotBundle\Entity\Application'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'silca_corsairerefcotbundle_application';
    }
}

和控制器:

public function editAction($id)
{
    $em = $this->getDoctrine()->getManager();

    $entity = $em->getRepository('SilcaCorsaireRefCotBundle:Application')->find($id);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Application entity.');
    }

    $editForm = $this->createEditForm($entity);
    $deleteForm = $this->createDeleteForm($id);

    return $this->render('SilcaCorsaireRefCotBundle:Application:edit.html.twig', array(
        'entity'      => $entity,
        'form'   => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    ));
    }

    private function createEditForm(Application $entity)
    {
        $form = $this->createForm(new ApplicationType(), $entity, array(
            'action' => $this->generateUrl('application_update', array('id' => $entity->getId())),
            'method' => 'PUT',
        ));

        $form->add('submit', 'submit', array('label' => 'Mettre à jour'));

        return $form;
    }

如果有人看到奇怪的东西,谢谢你的帮助!

0 个答案:

没有答案