1

我得到了以下实体

use Gedmo\Timestampable\Traits\TimestampableEntity;

/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 * @UniqueEntity(fields="email", message="Email already taken")
 */
class User
{
    /**
     * Hook timestampable behavior
     * updates createdAt, updatedAt fields
     */
    use TimestampableEntity;

...

如果我跑

$ php app/console doctrine:mapping:info

我得到这个错误

found 8 mapped entities:
[OK]   Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation
[OK]   Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation
[OK]   Gedmo\Translatable\Entity\Translation
[OK]   Gedmo\Loggable\Entity\MappedSuperclass\AbstractLogEntry
[OK]   Gedmo\Loggable\Entity\LogEntry
[OK]   Gedmo\Tree\Entity\MappedSuperclass\AbstractClosure
[OK]   Psren\CmsBundle\Entity\Group



  [Doctrine\Common\Annotations\AnnotationException]                                                                                                                                                    
  [Semantical Error] The annotation "@Gedmo\Timestampable" in property Psren\CmsBundle\Entity\User::$createdAt was never imported. Did you maybe forget to add a "use" statement for this annotation?

注释 @Gedmo\Timestampable 是在扩展的特征中定义的。所以它必须已经加载。

什么地方出了错?感谢帮助。

4

1 回答 1

3

:-)

我只是忘了加载注释。

use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity;

/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 * @UniqueEntity(fields="email", message="Email already taken")
 */
class User
{
    /**
     * Hook timestampable behavior
     * updates createdAt, updatedAt fields
     */
    use TimestampableEntity;
于 2012-12-14T16:18:34.027 回答