我搜索几小时以找到解决此问题的解决方案,但没有运气。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()
方法时才会触发错误。
能否请编辑您的帖子,并显示完整的代码和发生问题。只显示您清除实体的代码/文件。谢谢! –