Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 原则EM-如何插入到列中_Php_Symfony_Join_Doctrine Orm - Fatal编程技术网

Php 原则EM-如何插入到列中

Php 原则EM-如何插入到列中,php,symfony,join,doctrine-orm,Php,Symfony,Join,Doctrine Orm,我有两个实体:俱乐部和用户。在用户实体中,我创建了多个表: /** * @ORM\ManyToMany(targetEntity="Club", inversedBy="users") * @ORM\JoinTable(name="sms_followers") **/ private $smsfollower; 现在我想向表中添加数据。我用这个: //Get the club (no error handling created $getclub = $this->em-&g

我有两个实体:俱乐部和用户。在用户实体中,我创建了多个表:

 /**
 * @ORM\ManyToMany(targetEntity="Club", inversedBy="users")
 * @ORM\JoinTable(name="sms_followers")
 **/
 private $smsfollower;
现在我想向表中添加数据。我用这个:

//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();
我不能完成这件事。。。有人能帮我吗


请尽可能简单地使用英语,我来自荷兰

您最可能想要的是在您已有的收藏中添加一个SmsFollower

//在您的用户权限中
公共功能俱乐部(俱乐部$Club)
{
$this->clubs->add($club);
}
//在您的俱乐部实体中
公共函数addSmsFollower(用户$User)
{
$this->sms\u followers->add($user);
}
然后,在实体管理器中,可以持久化对象,然后刷新以保存它们


小贴士:我给这些领域命名为sms_追随者和俱乐部(复数,meervoud),因为这是一种多对多的关系

你能给我举个例子吗?在你的例子中是:$getclub->addSmsfollower($getuser)$这->em->坚持($getclub)$这->em->flush();您应该阅读Doctrine2文档中关于这一点的内容:谢谢!这对我帮助很大。我如何从该表中检索数据?我做对了两次,但第三次做不好