2016-11-03 4 views
1

この問題の解決策を見つけるのに数時間は掛かりますが運がありません。issetまたは空のDoctrineの不正なオフセットタイプ

多分これは重複投稿ですが、私はそれを見つけられませんでした。

だから、私はこのエラーを得たclear($entityname)方法エンティティ・マネージャを呼び出すときに、symfonyのサービスに問題があります。

Warning: Illegal offset type in isset or empty. 

私は見当もつかないなぜこの出来事を持っていません。

私がclear()メソッドをコメントすると、すべて正常に機能します。

まず、私はそこにプロダクトIDを取得するために必要とするいくつかのアクションがあるので、私が最初に必要があるため、新製品

$productRepo = new Products(); 
$productRepo->setCarmodels(json_encode($data['ModelId'])); 
$productRepo->setCategoryid($category); 
$productRepo->setDescription($data['Description']); 
$productRepo->setDiscount($data['Discount']); 
$productRepo->setDiscountprice($data['DiscountPrice']); 
$this->em->persist($productRepo); 
$this->em->flush($productRepo); 
$insertOther = $this->update($productRepo->getId(), $data); 
$this->em->clear($productRepo); 

insertAnotferコールアップデートを設定ProductHandlerを呼び出すその後ProductController

public function postProductAction(Request $request) 
{ 
    if($jsonData = $this->requestToArray($request)){ 
     $productHandler = $this->get("admin.product_handler"); 
     $insertNews = $productHandler->insert($jsonData); 
     if($insertNews === true) { 
      return $this->jsonResponse->setData(array(
      "status" => true, "msg" => MessageConstants::SUCCESS_SEND_DATA)); 
     } 
    } 
    $this->jsonResponse->setStatusCode(204); 
    return $this->jsonResponse->setData(
    array("status" => false, "msg" => MessageConstants::FAILED_RECEIVE_RESPONSE)); 
} 

を呼び出します挿入してから更新します。アップデートで

$product = $productRepo->find((int)$id); 
$product->setCarmodels(json_encode($data['ModelId'])); 
$product->setCategoryid($category); 
$product->setDescription($data['Description']); 
$product->setDiscount($data['Discount']); 
$product->setDiscountprice($data['DiscountPrice']); 

私も

$this->em->flush($product); 
$this->em->clear($product); 

明確なメソッドを呼び出します。そして、私はこのエラーを取得します。私は更新から明確なメソッドを削除しようとしたが運がない。挿入機能でエンティティなしのclear()メソッドを設定した場合にのみ、エラーはトリガされません。

+0

あなたの投稿を編集し、完全なコード、どこに問題が発生したを示してもらえ。あなたがエンティティをクリアしているところで、コード/ファイルのみを表示してください。ありがとう! –

答えて

1

のEntityManager :: clearメソッドは、エンティティタイプではなく、エンティティの実際のインスタンスの名前をとります。

\教義\ ORM \ EntityManagerの

/** 
* Clears the EntityManager. All entities that are currently managed 
* by this EntityManager become detached. 
* 
* @param string|null $entityName if given, only entities of this type will get detached 
* 
* @return void 
*/ 
public function clear($entityName = null) 
{ 
    $this->unitOfWork->clear($entityName); 
} 

それは何のように思えますデタッチが必要です - エンティティマネージャからエンティティインスタンスを分離する正しい方法: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-objects.html#detaching-entities

\教義\ ORM \ EntityManagerの

/** 
* Detaches an entity from the EntityManager, causing a managed entity to 
* become detached. Unflushed changes made to the entity if any 
* (including removal of the entity), will not be synchronized to the database. 
* Entities which previously referenced the detached entity will continue to 
* reference it. 
* 
* @param object $entity The entity to detach. 
* 
* @return void 
* 
* @throws ORMInvalidArgumentException 
*/ 
public function detach($entity) 
{ 
    if (! is_object($entity)) { 
     throw ORMInvalidArgumentException::invalidObject('EntityManager#detach()' , $entity); 
    } 

    $this->unitOfWork->detach($entity); 
} 
0

flushまたはclear関数のいずれかでパラメータを指定する必要があるとは思いません。

は、あなたが(パラメータとして実体なし)このように試してみました:

$this->em->flush(); 
$this->em->clear(); 

をそれがあなたのために働くかどうかは定かではないんだけど、あなたはそれを試してみて、それが助けかどうかを確認することができますか?私はこれについて間違っている可能性がありますので、誰かがより良い提案をしている場合は、投稿してください。

+0

私はupdateメソッドからclearを削除し、あなたが提案したようにflushとclearを呼び出すだけで動作します。しかし、問題は解決されていません。私はこれらのメソッドを更新する必要があるからです。 –

関連する問題