0
我試圖自動將當前user_id添加到created_by或updated_by字段中。 但我似乎無法獲得當前的user_id到另一個表的實體。 我使用FOSUserBundle ....在Symfony 2中自動更新created_by和updated_by值
/**
* @ORM\PrePersist
*/
public function setCreatedByValue()
{
if(!$this->getCreatedBy())
{
$user= $this->container->get('security.context')->getToken()->getUser();
$this->created_by = $user->getId();
}
}
這將拋出一個未定義的屬性:?.....集裝箱錯誤:-(
如何訪問當前用戶ID
感謝您的幫助。
我可能要對工作一段時間,真的不明白這一點。 – ldrocks
是什麼?你能更清楚嗎? – Florian
我對symfony不是很有經驗。對我來說似乎很複雜:-) – ldrocks