Search code examples
phpformssymfonydtosymfony-3.4

Symfony 3 DTOOneCommand changing null value to 0 after handleRequest


I am working on a Symfony 3 project and I am facing a problem. When my form is submitted it changed the value from null to zero. But I would like that it keeps value it is sent. Because for me null is different than 0.

I have dump like (form use create form from scenarioProposalVersionModelizeCommand):

    dump($scenarioProposalVersionModelizeCommand->phaseProposalVersions[0]);
    $form->handleRequest($request);
    dump($scenarioProposalVersionModelizeCommand->phaseProposalVersions[0]);die;

Output so this 3 last values as you can see are transformed:

enter image description here


Solution

  • I was going over the problem by using directly information from request.

    Using php condition to treat the value: ""

    if(empty($value) && strlen($value) == 0)
      $value = null;
    

    But question is still valid.