1

我正在尝试使用 Doctrine Extensions 中的 Timestampable 行为,我安装了 StofDoctrineExtensionsBundle 来帮助我解决这个问题。但是当我制作我的 YML 方案并运行生成实体命令时,一切都运行没有错误,但是在生成的 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。

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

谢谢你的帮助。

卢克

4

1 回答 1

0

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

    lifecycleCallbacks:
        postPersist: doSomething
        # callback   # method in entity

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

于 2013-03-31T04:34:18.507 回答