2017-08-03 52 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唉不是一個單一的實體

相關問題