0

我有一个对某些字段进行自定义验证的用户类。当我提交表单时,我收到以下错误:

警告:class_parents() [function.class-parents]:类不存在,无法加载到 ..../vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php 第 223 行

有人可以告诉我我做错了什么吗?

这是我的用户类:

<?php
namespace MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;
use Symfony\Component\Validator\Constraints as Assert;
use MyBundle\Validation\Constraint as MyAssert;


/**
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 */
class User extends BaseUser
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\generatedValue(strategy="AUTO")
     */
    protected $id;

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

    /**
     * @var string $email
     * @Assert\NotBlank(groups={"registration"})
     * @Assert\Email(groups={"registration"})
     * @MyAssert\Unique(groups={"registration"})
     */
    protected $email;
   .... 

堆栈跟踪:

in /myApp/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php at line 65    
at ErrorHandler ->handle ('2', 'class_parents() [<a href='function.class-parents'>function.class-parents</a>]: Class does not exist and could not be loaded', '/myApp/vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php', '223', array('name' => '', 'parentClasses' => array())) 
at class_parents ('') 
in /myApp/vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php at line 223    
at ClassMetadataFactory ->getParentClasses ('') 
in /myApp/vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php at line 246    
at ClassMetadataFactory ->loadMetadata ('') 
in /myApp/vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php at line 170    
at ClassMetadataFactory ->getMetadataFor ('') 
in /myApp/vendor/doctrine/lib/Doctrine/ORM/EntityManager.php at line 257    
at EntityManager ->getClassMetadata ('') 
in /myApp/vendor/doctrine/lib/Doctrine/ORM/EntityManager.php at line 574    
at EntityManager ->getRepository (null) 
in /myApp/src/comp/MyAppBundle/Validation/Constraint/UniqueValidator.php at line 21    
at UniqueValidator ->isValid ('asdfasdf', object(Unique)) 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 176    
at GraphWalker ->walkConstraint (object(Unique), 'asdfasdf', 'registration', 'data.email') 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 136    
at GraphWalker ->walkMember (object(PropertyMetadata), 'asdfasdf', 'registration', 'data.email', null) 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 119    
at GraphWalker ->walkProperty (object(ClassMetadata), 'email', object(User), 'registration', 'data.email', null) 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 111    
at GraphWalker ->walkObjectForGroup (object(ClassMetadata), object(User), 'registration', 'data') 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 82    
at GraphWalker ->walkObject (object(ClassMetadata), object(User), 'registration', 'data') 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 162    
at GraphWalker ->walkReference (object(User), 'registration', 'data', true) 
in /myApp/vendor/symfony/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php at line 125    
at DelegatingValidator ::validateFormData (object(Form), object(ExecutionContext)) 
at call_user_func (array('Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator', 'validateFormData'), object(Form), object(ExecutionContext)) 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/Constraints/CallbackValidator.php at line 65    
at CallbackValidator ->isValid (object(Form), object(Callback)) 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 176    
at GraphWalker ->walkConstraint (object(Callback), object(Form), 'Default', '') 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 104    
at GraphWalker ->walkObjectForGroup (object(ClassMetadata), object(Form), 'Default', '') 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php at line 82    
at GraphWalker ->walkObject (object(ClassMetadata), object(Form), 'Default', '') 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/Validator.php at line 62    
at Symfony\Component\Validator\{closure} (object(GraphWalker), 'Default') 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/Validator.php at line 120    
at Validator ->validateGraph (object(Form), object(Closure), null) 
in /myApp/vendor/symfony/src/Symfony/Component/Validator/Validator.php at line 65    
at Validator ->validate (object(Form)) 
in /myApp/vendor/symfony/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php at line 79    
at DelegatingValidator ->validate (object(Form)) 
in /myApp/vendor/symfony/src/Symfony/Component/Form/Form.php at line 556    
at Form ->bind (array('firstname' => '', 'lastname' => '', 'username' => '', 'email' => 'asdfasdf', 'plainPassword' => array('Passwort' => '', 'Passwort wiederholen' => ''), 'code' => '', 'plan' => '10', 'phone' => '', 'street' => '', 'zip' => '', 'city' => '', 'country' => '1')) 
in /myApp/vendor/symfony/src/Symfony/Component/Form/Form.php at line 592    
at Form ->bindRequest (object(Request)) 
in /myApp/src/comp/MyAppBundle/Controller/IndexController.php at line 151    
at IndexController ->registerAction () 
at call_user_func_array (array(object(IndexController), 'registerAction'), array()) 
in kernel.root_dir/cache/dev_local/classes.php at line 3905    
at HttpKernel ->handleRaw (object(Request), '1') 
in kernel.root_dir/cache/dev_local/classes.php at line 3875    
at HttpKernel ->handle (object(Request), '1', true) 
in kernel.root_dir/cache/dev_local/classes.php at line 4879    
at HttpKernel ->handle (object(Request), '1', true) 
in kernel.root_dir/bootstrap.php.cache at line 547    
at Kernel ->handle (object(Request)) 
in /myApp/web/app_dev_local.php at line 10    
4

1 回答 1

1
at EntityManager ->getRepository (null) 
in /myApp/src/comp/MyAppBundle/Validation/Constraint/UniqueValidator.php at line 21    
at UniqueValidator ->isValid ('asdfasdf', object(Unique))

错误的原因是使用空值调用EntityManager->getRepository() 。您的 UniqueValidator.php 似乎存在一些问题,如果没有该文件,无法准确判断问题所在。

于 2012-09-20T06:09:45.030 回答