Php 形式为Symfony的大量ArrrayCollection

Php 形式为Symfony的大量ArrrayCollection,php,forms,symfony,doctrine-orm,Php,Forms,Symfony,Doctrine Orm,我在一个Symfony项目中工作,我有两种类型的用户客户端和雇员客户端,它们都有自己的实体 创建/编辑用户时,可以将EmployeeSpie链接到客户端。 这就是我的问题所在,当我编辑或创建一个用户时,我可以创建一个用户,但我的表中没有存储任何东西,这使得我的表客户机和EmployeeSpie之间存在链接 以下是我所做的: 我的实体客户具有以下特征: 类客户端扩展用户 { /** *@ORM\ManyToMany(targetEntity=EmployeSpie::class,mappedBy=

我在一个Symfony项目中工作,我有两种类型的用户客户端和雇员客户端,它们都有自己的实体

创建/编辑用户时,可以将EmployeeSpie链接到客户端。 这就是我的问题所在,当我编辑或创建一个用户时,我可以创建一个用户,但我的表中没有存储任何东西,这使得我的表客户机和EmployeeSpie之间存在链接

以下是我所做的:
我的实体客户具有以下特征:

类客户端扩展用户
{
/**
*@ORM\ManyToMany(targetEntity=EmployeSpie::class,mappedBy=“clients”,cascade={“persist”})
*/
私人$雇员;
/**
*@return Collection | employeespie[]
*/
公共函数getEmployeSpies():集合
{
返回$this->employeSpies;
}
公共函数addEmployeSpy(employeSpy$employeSpy):self
{
如果(!$this->employeespies->包含($employeespies)){
$this->employeespies[]=$employeespy;
$employeSpy->addClientEmploye($this);
}
退还$this;
}
公共功能removeEmployeSpy(employeSpy$employeSpy):self
{
如果($this->employeespies->包含($employeespies)){
$this->employeespy->removeement($employeespy);
$employeSpy->removeClientEmploye($this);
}
退还$this;
}
}
我的桌子上的员工是:

class EmployeSpie扩展了用户
{
/**
*@ORM\ManyToMany(targetEntity=Client::class,inversedBy=“employeespies”)
*/
私人客户;
/**
*@return Collection | Client[]
*/
公共函数getClients():集合
{
返回$this->clients;
}
公共函数addClient(Client$Client):self
{
如果(!$this->clients->contains($client)){
$this->clients[]=$client;
}
退还$this;
}
公共函数removeClient(客户端$Client):self
{
如果($this->clients->contains($client)){
$this->clients->removelement($client);
}
退还$this;
}
公共函数
{
返回$this->getPrenom()。“”.$this->getNom();
}
我的表格是用Symfony表格制作的:

class ClientType扩展了AbstractType
{
公共函数buildForm(FormBuilderInterface$builder、array$options)
{
$builder
->添加('电子邮件')
->添加('密码')
->添加('nom')
->添加('prenom')
->添加('电话')
->添加('传真')
->添加('is_active')
->添加(“客户方行动”)
->添加('站点')
->添加('EmployeeSpies',EntityType::类,数组(
'class'=>EmployeeSpie::class,
“标签”=>“选择客户”,
“扩展”=>false,
“多个”=>true,
))
;
}
公共函数配置选项(选项解析器$resolver)
{
$resolver->setDefaults([
“数据类”=>客户端::类,
]);
}
}
在我的控制器中,我做了以下事情:

/**
*@Route(“/admin/clients/create”,name=“admin.client.new”)
*@param Request$Request
*@return-Response | Response
*/
新公共函数(Request$Request,UserPasswordEncoderInterface$passwordEncoder)
{
$client=新客户端();
$form=$this->createForm(ClientType::class,$client);
$form->handleRequest($request);
如果($form->isSubmitted()&&&$form->isValid())
{
$client->setRoles(数组('ROLE_CUSTOMER');
$client->setPassword(
$passwordEncoder->encodePassword(
$client,
$form->get('password')->getData()
)
);
$this->em->persist($client);
$this->em->flush();
$this->addFlash('success','Nouveau client crée avec success');
$this->redirectToRoute('admin.clients.index');
}
返回$this->render(“admin/clients/create.html.twig”[
“客户端”=>$client,
'form'=>$form->createView()
]);
}
/**
*@Route(“/admin/clients/{id}”,name=“admin.client.edit”,methods=“GET | POST”)
*@param Client$Client
*@返回响应
*/
公共函数编辑(客户端$Client,请求$Request,用户密码编码器接口$passwordEncoder)
{
$form=$this->createForm(ClientType::class,$client);
$form->handleRequest($request);
如果($form->isSubmitted()&&&$form->isValid())
{
$clientEmploye=$request->request->get('client');
$clientEmploye=$clientEmploye['employeSpies'];
$client->setPassword(
$passwordEncoder->encodePassword(
$client,
$form->get('password')->getData()
)
);
foreach($form->get('employeSpies')->getData()作为$employe){
$client->addEmployeSpy($employe);
}
$client->setRoles(数组('ROLE_CUSTOMER');
$this->em->flush();
$this->addFlash('success','Nouveau client modifiéavec success');
$this->redirectToRoute('admin.clients.index');
}
返回$this->render(“admin/clients/edit.html.twig”[
“客户端”=>$client,
'form'=>$form->createView()
]);
}

Si我的用户是正常创建或编辑的,但我没有在我的表单中存储
员工信息的链接。你知道为什么吗?

我找到了问题的答案。 @雅库米是对的,但几乎不需要其他改变

在我的客户实体中,我必须更改:

public function addEmployeSpy(employeSpy$employeSpy):self
{
如果(!$this->employeespies->包含($employeespies)){
$this->emplo