1
我與教條2實體:俱樂部和用戶。在用戶權限我創建了一個manytomany表:Doctrine EM - 如何插入列
/**
* @ORM\ManyToMany(targetEntity="Club", inversedBy="users")
* @ORM\JoinTable(name="sms_followers")
**/
private $smsfollower;
現在我wanne添加數據到表中。我用這個:
//Get the club (no error handling created
$getclub = $this->em->getRepository('Club')->findOneBy(array('id' => $clubid));
//Get the user by login ID
$getuser = $this->em->getRepository('User')->findOneBy(array('id' => '7'));
//Insert the userID and ClubID to the table sms_followers
$getuser = $getclub->addSmsfollower();
我無法做到這一點......任何人都可以幫助我嗎?
請保持英語儘可能容易,我可是從荷蘭
你有請給我一個例子嗎? –
在你的情況下它會是:$ getclub-> addSmsfollower($ getuser); $這 - > EM->堅持($ getclub); $這 - > EM->沖洗();您應該閱讀關於此的Doctrine2文檔:http://docs.doctrine-project.org/en/2.0.x/reference/working-with-objects.html#persisting-entities –
謝謝!這幫了我很多。 –