2017-08-03 33 views
0

我在symfony或doctrine中遇到问题。 我有一个实体notificationsettinggroupdetailnotificationsettinggroup学说(Symfony3)可捕捉的致命错误:传递给(bundle)的参数1必须是(bundle)的一个实例,数组给出

Notificationsettinggroup and 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); 

哪里是我的错?

回答

1

你传递一个数组不是实体,如果你不想要编辑的控制器试试这个:如果你想改变控制器试试这个(如果实施)

public function removeNotificationSettingGroupDetail(array $notificationSettingGroupDetails) 
{ 
    foreach (notificationSettingGroupDetails as notificationSettingGroupDetail) { 
     $this->NotificationSettingGroupDetail->removeElement($notificationSettingGroupDetail); 
    } 
} 

相反:

findOneNotificationGroupSettingDetailByMaster 

,而不是这样的:

findNotificationGroupSettingDetailByMaster 

因为findNotificationGroupSettingDetailByMaster回报的ARR唉不是一个单一的实体

相关问题