Symfony2 Doctrine Extensions从YML生成实体

时间:2013-03-30 15:53:20

标签: symfony doctrine-orm

我正在尝试使用Doctrine Extensions中的Timestampable行为,我安装了StofDoctrineExtensionsBundle来帮助我。但是当我制作我的YML方案并运行generate entities命令时,一切都运行没有错误,但是在生成的php类中没有出现Gedmo / DoctrineExtensions注释。我做错了什么?

这是我用于我想制作的简单问题跟踪器的YML文件(Issue.orm.yml):

Theta\IssueTrackerBundle\Entity\Issue:
  type: entity
  table: issues
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    category:
      type: string
      length: 16
    created_at:
      type: datetime
      gedmo:
        timestampable:
          on: create
    updated_at:
      type: datetime
      gedmo:
        timestampable:
          on: update
    closed_at:
      type: datetime
      gedmo:
        timestampable
    title:
      type: string
      length: 64
  oneToOne:
    user_id:
      targetEntity: ThetaUserBundle\User
    assigned_to:
      targetEntity: ThetaUserBundle\User

这是生成的php类(Issue.php):     

namespace Theta\IssueTrackerBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Issue
 */
class Issue
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $category;

    /**
     * @var \DateTime
     */
    private $created_at;

    /**
     * @var \DateTime
     */
    private $updated_at;

    /**
     * @var \DateTime
     */
    private $closed_at;

    /**
     * @var string
     */
    private $title;

    /**
     * @var \ThetaUserBundle\User
     */
    private $user_id;

    /**
     * @var \ThetaUserBundle\User
     */
    private $assigned_to;


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

    /**
     * Set category
     *
     * @param string $category
     * @return Issue
     */
    public function setCategory($category)
    {
        $this->category = $category;

        return $this;
    }

    /**
     * Get category
     *
     * @return string 
     */
    public function getCategory()
    {
        return $this->category;
    }

    /**
     * Set created_at
     *
     * @param \DateTime $createdAt
     * @return Issue
     */
    public function setCreatedAt($createdAt)
    {
        $this->created_at = $createdAt;

        return $this;
    }

    /**
     * Get created_at
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->created_at;
    }

    /**
     * Set updated_at
     *
     * @param \DateTime $updatedAt
     * @return Issue
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updated_at = $updatedAt;

        return $this;
    }

    /**
     * Get updated_at
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updated_at;
    }

    /**
     * Set closed_at
     *
     * @param \DateTime $closedAt
     * @return Issue
     */
    public function setClosedAt($closedAt)
    {
        $this->closed_at = $closedAt;

        return $this;
    }

    /**
     * Get closed_at
     *
     * @return \DateTime 
     */
    public function getClosedAt()
    {
        return $this->closed_at;
    }

    /**
     * Set title
     *
     * @param string $title
     * @return Issue
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Set user_id
     *
     * @param \ThetaUserBundle\User $userId
     * @return Issue
     */
    public function setUserId(\ThetaUserBundle\User $userId = null)
    {
        $this->user_id = $userId;

        return $this;
    }

    /**
     * Get user_id
     *
     * @return \ThetaUserBundle\User 
     */
    public function getUserId()
    {
        return $this->user_id;
    }

    /**
     * Set assigned_to
     *
     * @param \ThetaUserBundle\User $assignedTo
     * @return Issue
     */
    public function setAssignedTo(\ThetaUserBundle\User $assignedTo = null)
    {
        $this->assigned_to = $assignedTo;

        return $this;
    }

    /**
     * Get assigned_to
     *
     * @return \ThetaUserBundle\User 
     */
    public function getAssignedTo()
    {
        return $this->assigned_to;
    }
}

时间戳行为没有出现在php类中,我不明白为什么。我按照说明将StofDoctrineExtensionsBundle安装到字母上,它似乎安装正确,但它没有做任何事情。我正在使用Symfony 2.2。

所以我的问题是:我期待一些不应该发生的事情,或者我做错了什么?

感谢您的帮助。

吕克

1 个答案:

答案 0 :(得分:0)

不确定它对StofDoctrineExtensions的工作方式是否相同,但通常需要将lifecyccallbacks放在yml中。

    lifecycleCallbacks:
        postPersist: doSomething
        # callback   # method in entity

然后注释和方法名称将与此匹配。