2017-05-18 13 views
1

Catchable Fatal Error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in /srv/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1060 and defined引数3は:: __構築物は()型の配列でなければなりません、ヌルコントローラではライン1060

にUnitOfWork.phpに呼び出され、与えられた

removeExpireProducts(); 
$em->flush(); 

インサイド私のサービス:このような下へ

function removeExpireProducts() 
{ 
    foreach ($products as $product) { 
     $this->productRemover->removeProduct($product); 
    } 
} 

productRemover class: 
public function removeProduct(Product $product) 
{ 

    $newOffer = 
     $this->offerGroup 
     ->createOffer($product); 

    if (null !== $newOffer) { 
     $this->em->persist($newOffer); 
     $this->em->flush(); 
    } 

    $this->em->remove($product); 
} 
+0

あなたはその上に同じ教義のイベントリスナーを持っていますか? – Matteo

+0

@Matteoはエンティティマネージャの同じオブジェクトを意味しますか? –

+0

私は[これ](http://symfony.com/doc/current/doctrine/event_listeners_subscribers.html)の一部のサービスは 'doctrine.event_listener'とタグ付けされています – Matteo

答えて

1

移動flush()

public function removeProduct(Product $product) 
{ 
    $newOffer = 
     $this->offerGroup 
     ->createOffer($product); 

    if (null !== $newOffer) { 
     $this->em->persist($newOffer); 
    } 

    $this->em->remove($product); 
    $this->em->flush(); 
} 

そして、あなたはこのループでflush()の実行を避けるために、あなたのコードをリファクタリングより$em->flush();

を削除するコントローラで3210:

foreach ($products as $product) { 
    $this->productRemover->removeProduct($product); 
}