在form-> handleRequest()和验证上Symfony上的模糊错误

时间:2016-08-09 08:05:16

标签: php forms symfony

我有一个Symfony 2.8.9应用程序,其中单个表单会在行上造成大的模糊错误

$form->handleRequest($request);

我的表单非常简单:只有一个id和一个commentaire字段。似乎在验证任务期间发生了错误(下面的完整描述)。

[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}class', attribute 'name': 'Symfony\Component\Form\Form' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 7, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}constraint', attribute 'name': 'Symfony\Component\Form\Extension\Validator\Constraints\Form' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 8, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}property', attribute 'name': 'children' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 9, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}constraint', attribute 'name': 'Valid' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 10, column 0)
500 Internal Server Error - MappingException
1 linked Exception: InvalidArgumentException »

[2/2] MappingException: [ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}class', attribute 'name': 'Symfony\Component\Form\Form' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 7, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}constraint', attribute 'name': 'Symfony\Component\Form\Extension\Validator\Constraints\Form' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 8, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}property', attribute 'name': 'children' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 9, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}constraint', attribute 'name': 'Valid' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 10, column 0)   -
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\XmlFileLoader.php at line 179   + 
at XmlFileLoader ->parseFile ('D:\Documents\workspace\MyProject\vendor\symfony\symfony\src\Symfony\Component\Form/Resources/config/validation.xml') 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\XmlFileLoader.php at line 40   + 
at XmlFileLoader ->loadClassMetadata (object(ClassMetadata)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\LoaderChain.php at line 57   + 
at LoaderChain ->loadClassMetadata (object(ClassMetadata)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\LoaderChain.php at line 57   + 
at LoaderChain ->loadClassMetadata (object(ClassMetadata)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory.php at line 128   + 
at LazyLoadingMetadataFactory ->getMetadataFor ('Traversable') 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory.php at line 124   + 
at LazyLoadingMetadataFactory ->getMetadataFor ('IteratorAggregate') 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory.php at line 124   + 
at LazyLoadingMetadataFactory ->getMetadataFor (object(Form)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Validator\RecursiveContextualValidator.php at line 343   + 
at RecursiveContextualValidator ->validateObject (object(Form), '', array('Default'), '1', object(ExecutionContext)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Validator\RecursiveContextualValidator.php at line 153   + 
at RecursiveContextualValidator ->validate (object(Form), null, false) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Validator\RecursiveValidator.php at line 132   + 
at RecursiveValidator ->validate (object(Form)) 
in vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener.php at line 68   + 
at ValidationListener ->validateForm (object(FormEvent), 'form.post_bind', object(EventDispatcher)) 
at call_user_func (array(object(ValidationListener), 'validateForm'), object(FormEvent), 'form.post_bind', object(EventDispatcher)) 
in app\cache\dev\classes.php at line 1858   + 
at EventDispatcher ->doDispatch (array(array(object(ValidationListener), 'validateForm'), array(object(DataCollectorListener), 'postSubmit')), 'form.post_bind', object(FormEvent)) 
in app\cache\dev\classes.php at line 1773   + 
at EventDispatcher ->dispatch ('form.post_bind', object(FormEvent)) 
in vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\ImmutableEventDispatcher.php at line 43   + 
at ImmutableEventDispatcher ->dispatch ('form.post_bind', object(FormEvent)) 
in vendor\symfony\symfony\src\Symfony\Component\Form\Form.php at line 660   + 
at Form ->submit (array('commentaire' => 'dqsdqs', 'save' => '', '_token' => 'FogMqUyv366NxySj8w1t4PLEI03pIc_V3eoiQ0tHesA'), true) 
in vendor\symfony\symfony\src\Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler.php at line 116   +
at HttpFoundationRequestHandler ->handleRequest (object(Form), object(Request)) 
in vendor\symfony\symfony\src\Symfony\Component\Form\Form.php at line 489   + 
at Form ->handleRequest (object(Request)) 
in src\MyBundle\Controller\CalendrierController.php at line 34   + 
at CalendrierController ->addAction (object(Request)) 
at call_user_func_array (array(object(CalendrierController), 'addAction'), array(object(Request))) 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 144   + 
at HttpKernel ->handleRaw (object(Request), '1') 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 64   + 
at HttpKernel ->handle (object(Request), '1', true) 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php at line 69   + 
at ContainerAwareHttpKernel ->handle (object(Request), '1', true) 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php at line 185   + 
at Kernel ->handle (object(Request)) 
in web\app_dev.php at line 30   + 

[1/2] InvalidArgumentException: [ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}class', attribute 'name': 'Symfony\Component\Form\Form' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 7, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}constraint', attribute 'name': 'Symfony\Component\Form\Extension\Validator\Constraints\Form' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 8, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}property', attribute 'name': 'children' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 9, column 0)
[ERROR 1824] Element '{http://symfony.com/schema/dic/constraint-mapping}constraint', attribute 'name': 'Valid' is not a valid value of the atomic type 'xs:time'. (in file:/D:/Documents/workspace/MyProject/web/ - line 10, column 0)   -
in vendor\symfony\symfony\src\Symfony\Component\Config\Util\XmlUtils.php at line 96   + 
at XmlUtils ::loadFile ('D:\Documents\workspace\MyProject\vendor\symfony\symfony\src\Symfony\Component\Form/Resources/config/validation.xml', 'D:\Documents\workspace\MyProject\vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd') 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\XmlFileLoader.php at line 177   + 
at XmlFileLoader ->parseFile ('D:\Documents\workspace\MyProject\vendor\symfony\symfony\src\Symfony\Component\Form/Resources/config/validation.xml') 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\XmlFileLoader.php at line 40   + 
at XmlFileLoader ->loadClassMetadata (object(ClassMetadata)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\LoaderChain.php at line 57   + 
at LoaderChain ->loadClassMetadata (object(ClassMetadata)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\LoaderChain.php at line 57   + 
at LoaderChain ->loadClassMetadata (object(ClassMetadata)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory.php at line 128   + 
at LazyLoadingMetadataFactory ->getMetadataFor ('Traversable') 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory.php at line 124   + 
at LazyLoadingMetadataFactory ->getMetadataFor ('IteratorAggregate') 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory.php at line 124   + 
at LazyLoadingMetadataFactory ->getMetadataFor (object(Form)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Validator\RecursiveContextualValidator.php at line 343   + 
at RecursiveContextualValidator ->validateObject (object(Form), '', array('Default'), '1', object(ExecutionContext)) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Validator\RecursiveContextualValidator.php at line 153   + 
at RecursiveContextualValidator ->validate (object(Form), null, false) 
in vendor\symfony\symfony\src\Symfony\Component\Validator\Validator\RecursiveValidator.php at line 132   + 
at RecursiveValidator ->validate (object(Form)) 
in vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener.php at line 68   + 
at ValidationListener ->validateForm (object(FormEvent), 'form.post_bind', object(EventDispatcher)) 
at call_user_func (array(object(ValidationListener), 'validateForm'), object(FormEvent), 'form.post_bind', object(EventDispatcher)) 
in app\cache\dev\classes.php at line 1858   + 
at EventDispatcher ->doDispatch (array(array(object(ValidationListener), 'validateForm'), array(object(DataCollectorListener), 'postSubmit')), 'form.post_bind', object(FormEvent)) 
in app\cache\dev\classes.php at line 1773   + 
at EventDispatcher ->dispatch ('form.post_bind', object(FormEvent)) 
in vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\ImmutableEventDispatcher.php at line 43   + 
at ImmutableEventDispatcher ->dispatch ('form.post_bind', object(FormEvent)) 
in vendor\symfony\symfony\src\Symfony\Component\Form\Form.php at line 660   + 
at Form ->submit (array('commentaire' => 'dqsdqs', 'save' => '', '_token' => 'FogMqUyv366NxySj8w1t4PLEI03pIc_V3eoiQ0tHesA'), true) 
in vendor\symfony\symfony\src\Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler.php at line 116   +
at HttpFoundationRequestHandler ->handleRequest (object(Form), object(Request)) 
in vendor\symfony\symfony\src\Symfony\Component\Form\Form.php at line 489   + 
at Form ->handleRequest (object(Request)) 
in src\MyBundle\Controller\CalendrierController.php at line 34   + 
at CalendrierController ->addAction (object(Request)) 
at call_user_func_array (array(object(CalendrierController), 'addAction'), array(object(Request))) 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 144   + 
at HttpKernel ->handleRaw (object(Request), '1') 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 64   + 
at HttpKernel ->handle (object(Request), '1', true) 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php at line 69   + 
at ContainerAwareHttpKernel ->handle (object(Request), '1', true) 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php at line 185   + 
at Kernel ->handle (object(Request)) 
in web\app_dev.php at line 30

控制器(仅限addAction方法):

public function addAction(Request $request)
{
    $calendrier = new Calendrier();
    $form = $this->createForm(CalendrierType::class, $calendrier);
    $hasError = false ;

    if ($request->isMethod('POST')) {
        // Here the error occurs
        $form->handleRequest($request);
    }

    return $this->render('MyBundle:Calendrier:add.html.twig', array(
        'form' => $form->createView()
    ));
}

表格(CalendrierType.php)     

namespace MyBundle\Form ;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CalendrierType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('commentaire', TextareaType::class, array('required' => false))
            ->add('save', SubmitType::class);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'MyBundle\Entity\Calendrier'
        ));
    }

    public function getBlockPrefix()
    {
        return 'mybundle_calendrier' ;
    }
}

我的 Calendrier实体(Calendrier.php):

<?php

namespace MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use MyBundle\Entity\AbstractEntity ;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Calendrier
 *
 * @ORM\Table(name="calendrier")
 * @ORM\Entity(repositoryClass="MyBundle\Repository\CalendrierRepository")
 */
class Calendrier extends AbstractEntity
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="commentaire", type="string", nullable=true)
     */
    private $commentaire;

    /************ Getters and setters ******/

     /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    public function getCommentaire() {
        return $this->commentaire;
    }

    public function setCommentaire($commentaire) {
        $this->commentaire = $commentaire;
        return $this;
    }
}

所有这一切都非常简单。我有另一个更大的实体/表单/控制器具有相同的错误,但两天前,它工作正常,我没有改变其他形式的任何东西,也没有在配置文件... ...

堆栈跟踪和Symfony错误消息对我来说太奇怪了,有人可以帮我吗?

1 个答案:

答案 0 :(得分:2)

我只是重新启动Apache服务器,然后错误消失了,而没有更改代码中的单个空格。