我在symfony或doctrine中遇到了问题。
我有一个实体notificationsettinggroupdetail
和notificationsettinggroup
。
Notificationsettinggroup
和notificationsettinggroup
是主要详细信息,并且在实体原则中具有连接条件。
当我想使用以下方法从主文件(notificationsetinggroup
)中删除数据详细信息时,问题就出现了:
/**
* Remove notificationSettingGroupDetail
*
* @param \Dsp\DspAdministrationBundle\Entity\notificationSettingGroupDetail $notificationSettingGroupDetail
*/
public function removeNotificationSettingGroupDetail(notificationSettingGroupDetail $notificationSettingGroupDetail)
{
$this->NotificationSettingGroupDetail->removeElement($notificationSettingGroupDetail);
}
但是当我使用它时,我收到了一些错误:
Catchable Fatal Error: Argument 1 passed to Dsp\DspAdministrationBundle\Entity\notificationSettingGroup::removeNotificationSettingGroupDetail() must be an instance of Dsp\DspAdministrationBundle\Entity\notificationSettingGroupDetail, array given, called in C:\xampp\htdocs\Symfony-DspWebApp\src\Dsp\DspAdministrationBundle\Controller\Api\ApiNotificationSettingGroupController.php on line 122 and defined
这是控制器中的代码:
$entityDetailDelete = $this->getDoctrine()->getRepository(notificationSettingGroupDetail::class)->findNotificationGroupSettingDetailByMaster($userOld[$i]['id']);
$entity->removeNotificationSettingGroupDetail($entityDetailDelete);
我的错在哪里?
答案 0 :(得分:1)
您传递的数组不是实体,如果您不想编辑控制器,请尝试以下操作:
public function removeNotificationSettingGroupDetail(array $notificationSettingGroupDetails)
{
foreach (notificationSettingGroupDetails as notificationSettingGroupDetail) {
$this->NotificationSettingGroupDetail->removeElement($notificationSettingGroupDetail);
}
}
相反,如果您想更改控制器,请尝试此操作(如果已实施):
findOneNotificationGroupSettingDetailByMaster
而不是:
findNotificationGroupSettingDetailByMaster
因为findNotificationGroupSettingDetailByMaster
返回的数组不是单个实体