我搜索幾小時以找到解決此問題的解決方案,但沒有運氣。isset或empty中的非法偏移類型原理清除
也許這是重複的帖子,但我沒有找到它。
所以,我在的Symfony的服務問題,當我打電話實體管理器clear($entityname)
方法我得到這個錯誤:
Warning: Illegal offset type in isset or empty.
我不知道爲什麼發生這種情況。
如果我評論clear()
方法,一切工作正常。
首先我打電話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));
}
然後調用ProductHandler
它集新產品
$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
呼叫更新,因爲有一些行動需要獲得產品ID,所以我首先需要插入然後做更新。
$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()
方法時纔會觸發錯誤。
能否請編輯您的帖子,並顯示完整的代碼和發生問題。只顯示您清除實體的代碼/文件。謝謝! –