Forms 提交表格Symfony 3后丢失以前的实体数据
这是我的控制器编辑操作的一部分。方法是Forms 提交表格Symfony 3后丢失以前的实体数据,forms,symfony,symfony-forms,Forms,Symfony,Symfony Forms,这是我的控制器编辑操作的一部分。方法是PUT public function editRentalAction(Request $request, Rental $rental): JsonResponse { $rentalManager = $this->get('rental.rental_manager'); $form = $this->createForm(RentalType::class, $rental); $form->subm
PUT
public function editRentalAction(Request $request, Rental $rental): JsonResponse
{
$rentalManager = $this->get('rental.rental_manager');
$form = $this->createForm(RentalType::class, $rental);
$form->submit(json_decode($request->getContent(), true));
当我试图从请求中提交一些实体数据(我想更新这些数据)时,所有其他实体数据都会丢失(设置为null
)。我怎样才能只更改我发送的这个参数
请求有效负载:
{"example_parameter": "example"}
PUT
将使空属性无效
最佳解决方案:使用PATCH
而不是PUT
public function editRentalAction(Request $request, Rental $rental): JsonResponse
{
$rentalManager = $this->get('rental.rental_manager');
$form = $this->createForm(RentalType::class, $rental);
$form->submit(json_decode($request->getContent(), true));
备选方案:使用
PUT
发送整个对象(不仅是更新的属性)。PUT
将使空属性无效
最佳解决方案:使用PATCH
而不是PUT
public function editRentalAction(Request $request, Rental $rental): JsonResponse
{
$rentalManager = $this->get('rental.rental_manager');
$form = $this->createForm(RentalType::class, $rental);
$form->submit(json_decode($request->getContent(), true));
备选方案:使用
PUT
发送整个对象(不仅仅是更新的属性)。解决方案在submit()
中的第二个参数设置为false
,并将方法更改为PATCH
下面是说明:解决方案在
submit()
中的第二个参数设置为false
,并将方法更改为PATCH
以下是描述:您确切使用的是哪个symfony版本?它是symfony 3.3您确切使用的symfony版本?它是symfony 3.3
PATH
有相同的问题PATH
有相同的问题