簡體   English   中英

Doctrine2如何設置Id值

[英]How does Doctrine2 set the Id values

我對一個關於Doctrine2內部運作的好奇心提出了一個問題。 我作為一個用戶看到了一個非常干凈和強大的界面,但在引擎蓋下工作必須有一些重要的魔力。

當我生成一個簡單的實體時,它看起來像這樣:

class SimpleEntity
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $title;

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

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

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

正如你會注意到有一件事顯然不存在,沒有辦法設置id,但是學說工廠返回帶有set id的實體。 這怎么可行? 我試圖查看源代碼,但在某個地方丟失了軌道。

如何在不在類層次結構中的情況下覆蓋受保護的值?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM